* Initial Commit for OAuth API This builds and run and return the right error. Need to test it and then adding all users as possible client * Added mising dependency * just compile already... * Fixing template test * Imrpovements Moved db stuff in models Added some tests Added form in modpanel to add/update a client Added controllers for add/update of client * Added Forms + speed improvements Controller oauth client listing + html Controller oauth client delete + messages Messages on comment delete New ES config that disable ES if set to false. Improve load speed on local development Fix a load config bug Fix index admin & translation string sign_out broken by @ewhal * Sanitize empty strig in form array + css Multiple empty array of strings are sanitized for the oauth client create form Added some css for the form display * Upload and Create form works * Fix splitting response types * Removing required on secret when updating * fix travis error * Fix travis template test * Update dependency * Moved to jinzhu instead of azhao * randomizen secret on creation * Final touch on oath api improved display name fix grant form csrf fix login csrf on oauth * Fix gorm test * fix template test * Fixing deleted dependency issue * Make travis faster * Fix typo * Fix csrf for api calls * This shouldn't be exempt * Removing hard coded hash @ewhal Don't forget to replace the hash in tokens.go with another one * Added an example on how to use OAuth middleware * Renamed fosite utils to oauth2 utils
68 lignes
2,3 Kio
Go
68 lignes
2,3 Kio
Go
package fosite
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"context"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func (c *Fosite) NewAuthorizeRequest(ctx context.Context, r *http.Request) (AuthorizeRequester, error) {
|
|
request := &AuthorizeRequest{
|
|
ResponseTypes: Arguments{},
|
|
HandledResponseTypes: Arguments{},
|
|
Request: *NewRequest(),
|
|
}
|
|
|
|
if err := r.ParseForm(); err != nil {
|
|
return request, errors.Wrap(ErrInvalidRequest, err.Error())
|
|
}
|
|
|
|
request.Form = r.Form
|
|
client, err := c.Store.GetClient(ctx, request.GetRequestForm().Get("client_id"))
|
|
if err != nil {
|
|
return request, errors.WithStack(ErrInvalidClient)
|
|
}
|
|
request.Client = client
|
|
|
|
// Fetch redirect URI from request
|
|
rawRedirURI, err := GetRedirectURIFromRequestValues(r.Form)
|
|
if err != nil {
|
|
return request, errors.Wrap(ErrInvalidRequest, err.Error())
|
|
}
|
|
|
|
// Validate redirect uri
|
|
redirectURI, err := MatchRedirectURIWithClientRedirectURIs(rawRedirURI, client)
|
|
if err != nil {
|
|
return request, errors.Wrap(ErrInvalidRequest, err.Error())
|
|
} else if !IsValidRedirectURI(redirectURI) {
|
|
return request, errors.Wrap(ErrInvalidRequest, "not a valid redirect uri")
|
|
}
|
|
request.RedirectURI = redirectURI
|
|
|
|
// https://tools.ietf.org/html/rfc6749#section-3.1.1
|
|
// Extension response types MAY contain a space-delimited (%x20) list of
|
|
// values, where the order of values does not matter (e.g., response
|
|
// type "a b" is the same as "b a"). The meaning of such composite
|
|
// response types is defined by their respective specifications.
|
|
request.ResponseTypes = removeEmpty(strings.Split(r.Form.Get("response_type"), " "))
|
|
|
|
// rfc6819 4.4.1.8. Threat: CSRF Attack against redirect-uri
|
|
// The "state" parameter should be used to link the authorization
|
|
// request with the redirect URI used to deliver the access token (Section 5.3.5).
|
|
//
|
|
// https://tools.ietf.org/html/rfc6819#section-4.4.1.8
|
|
// The "state" parameter should not be guessable
|
|
state := r.Form.Get("state")
|
|
if len(state) < MinParameterEntropy {
|
|
// We're assuming that using less then 8 characters for the state can not be considered "unguessable"
|
|
return request, errors.Wrapf(ErrInvalidState, "state length must at least be %d characters long", MinParameterEntropy)
|
|
}
|
|
request.State = state
|
|
|
|
// Remove empty items from arrays
|
|
request.SetRequestedScopes(removeEmpty(strings.Split(r.Form.Get("scope"), " ")))
|
|
return request, nil
|
|
}
|