本文整理匯總了Golang中github.com/ory-am/fosite.AccessRequester.SetGrantTypeHandled方法的典型用法代碼示例。如果您正苦於以下問題:Golang AccessRequester.SetGrantTypeHandled方法的具體用法?Golang AccessRequester.SetGrantTypeHandled怎麽用?Golang AccessRequester.SetGrantTypeHandled使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ory-am/fosite.AccessRequester
的用法示例。
在下文中一共展示了AccessRequester.SetGrantTypeHandled方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ValidateTokenEndpointRequest
// ValidateTokenEndpointRequest implements https://tools.ietf.org/html/rfc6749#section-6
func (c *RefreshTokenGrantHandler) ValidateTokenEndpointRequest(_ context.Context, req *http.Request, request fosite.AccessRequester, session interface{}) error {
// grant_type REQUIRED.
// Value MUST be set to "client_credentials".
if request.GetGrantType() != "refresh_token" {
return nil
}
// The authorization server MUST ... validate the refresh token.
challenge := new(enigma.Challenge)
challenge.FromString(req.Form.Get("refresh_token"))
if err := c.Enigma.ValidateChallenge(request.GetClient().GetHashedSecret(), challenge); err != nil {
return errors.New(fosite.ErrInvalidRequest)
}
ar, err := c.Store.GetRefreshTokenSession(challenge.Signature, &core.TokenSession{Extra: session})
if err == pkg.ErrNotFound {
return errors.New(fosite.ErrInvalidRequest)
} else if err != nil {
return errors.New(fosite.ErrServerError)
}
// The authorization server MUST ... and ensure that the refresh token was issued to the authenticated client
if ar.GetClient().GetID() != request.GetClient().GetID() {
return errors.New(fosite.ErrInvalidRequest)
}
request.SetGrantTypeHandled("refresh_token")
return nil
}
示例2: ValidateTokenEndpointRequest
// ValidateTokenEndpointRequest implements https://tools.ietf.org/html/rfc6749#section-6
func (c *RefreshTokenGrantHandler) ValidateTokenEndpointRequest(ctx context.Context, req *http.Request, request fosite.AccessRequester) error {
// grant_type REQUIRED.
// Value MUST be set to "client_credentials".
if request.GetGrantType() != "refresh_token" {
return nil
}
// The authorization server MUST ... validate the refresh token.
signature, err := c.RefreshTokenStrategy.ValidateRefreshToken(req.Form.Get("refresh_token"), ctx, req, request)
if err != nil {
return errors.New(fosite.ErrInvalidRequest)
}
accessRequest, err := c.Store.GetRefreshTokenSession(signature, nil)
if err == pkg.ErrNotFound {
return errors.New(fosite.ErrInvalidRequest)
} else if err != nil {
return errors.New(fosite.ErrServerError)
}
// The authorization server MUST ... and ensure that the refresh token was issued to the authenticated client
if accessRequest.GetClient().GetID() != request.GetClient().GetID() {
return errors.New(fosite.ErrInvalidRequest)
}
request.SetGrantTypeHandled("refresh_token")
return nil
}
示例3: ValidateTokenEndpointRequest
// ValidateTokenEndpointRequest implements https://tools.ietf.org/html/rfc6749#section-4.4.2
func (c *ClientCredentialsGrantHandler) ValidateTokenEndpointRequest(_ context.Context, req *http.Request, request fosite.AccessRequester, session interface{}) error {
// grant_type REQUIRED.
// Value MUST be set to "client_credentials".
if request.GetGrantType() != "client_credentials" {
return nil
}
// The client MUST authenticate with the authorization server as described in Section 3.2.1.
// This requirement is already fulfilled because fosite requries all token requests to be authenticated as described
// in https://tools.ietf.org/html/rfc6749#section-3.2.1
// There's nothing else to do. All other security considerations are for the client side.
request.SetGrantTypeHandled("client_credentials")
return nil
}
示例4: ValidateTokenEndpointRequest
// ValidateTokenEndpointRequest implements https://tools.ietf.org/html/rfc6749#section-4.3.2
func (c *ResourceOwnerPasswordCredentialsGrantHandler) ValidateTokenEndpointRequest(_ context.Context, req *http.Request, request fosite.AccessRequester, session interface{}) error {
// grant_type REQUIRED.
// Value MUST be set to "password".
if request.GetGrantType() != "password" {
return nil
}
username := req.PostForm.Get("username")
password := req.PostForm.Get("password")
if username == "" || password == "" {
return errors.New(fosite.ErrInvalidRequest)
} else if err := c.Store.DoCredentialsAuthenticate(username, password); err == pkg.ErrNotFound {
return errors.New(fosite.ErrInvalidRequest)
} else if err != nil {
return errors.New(fosite.ErrServerError)
}
request.SetGrantTypeHandled("password")
return nil
}