本文整理匯總了Golang中github.com/ory-am/fosite.AccessRequester.SetSession方法的典型用法代碼示例。如果您正苦於以下問題:Golang AccessRequester.SetSession方法的具體用法?Golang AccessRequester.SetSession怎麽用?Golang AccessRequester.SetSession使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ory-am/fosite.AccessRequester
的用法示例。
在下文中一共展示了AccessRequester.SetSession方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: HandleTokenEndpointRequest
// HandleTokenEndpointRequest implements
// * https://tools.ietf.org/html/rfc6749#section-4.1.3 (everything)
func (c *AuthorizeExplicitGrantHandler) HandleTokenEndpointRequest(ctx context.Context, r *http.Request, request fosite.AccessRequester) error {
// grant_type REQUIRED.
// Value MUST be set to "authorization_code".
if !request.GetGrantTypes().Exact("authorization_code") {
return errors.Wrap(fosite.ErrUnknownRequest, "")
}
if !request.GetClient().GetGrantTypes().Has("authorization_code") {
return errors.Wrap(fosite.ErrInvalidGrant, "The client is not allowed to use grant type authorization_code")
}
code := r.PostForm.Get("code")
signature := c.AuthorizeCodeStrategy.AuthorizeCodeSignature(code)
authorizeRequest, err := c.AuthorizeCodeGrantStorage.GetAuthorizeCodeSession(ctx, signature, request.GetSession())
if errors.Cause(err) == fosite.ErrNotFound {
return errors.Wrap(fosite.ErrInvalidRequest, err.Error())
} else if err != nil {
return errors.Wrap(fosite.ErrServerError, err.Error())
}
// The authorization server MUST verify that the authorization code is valid
if err := c.AuthorizeCodeStrategy.ValidateAuthorizeCode(ctx, request, code); err != nil {
return errors.Wrap(fosite.ErrInvalidRequest, err.Error())
}
// Override scopes
request.SetRequestedScopes(authorizeRequest.GetRequestedScopes())
// The authorization server MUST ensure that the authorization code was issued to the authenticated
// confidential client, or if the client is public, ensure that the
// code was issued to "client_id" in the request,
if authorizeRequest.GetClient().GetID() != request.GetClient().GetID() {
return errors.Wrap(fosite.ErrInvalidRequest, "Client ID mismatch")
}
// ensure that the "redirect_uri" parameter is present if the
// "redirect_uri" parameter was included in the initial authorization
// request as described in Section 4.1.1, and if included ensure that
// their values are identical.
forcedRedirectURI := authorizeRequest.GetRequestForm().Get("redirect_uri")
if forcedRedirectURI != "" && forcedRedirectURI != r.PostForm.Get("redirect_uri") {
return errors.Wrap(fosite.ErrInvalidRequest, "Redirect URI mismatch")
}
// Checking of POST client_id skipped, because:
// If the client type is confidential or the client was issued client
// credentials (or assigned other authentication requirements), the
// client MUST authenticate with the authorization server as described
// in Section 3.2.1.
request.SetSession(authorizeRequest.GetSession())
request.GetSession().SetExpiresAt(fosite.AccessToken, time.Now().Add(c.AccessTokenLifespan))
return nil
}
示例2: HandleTokenEndpointRequest
// HandleTokenEndpointRequest implements https://tools.ietf.org/html/rfc6749#section-6
func (c *RefreshTokenGrantHandler) HandleTokenEndpointRequest(ctx context.Context, req *http.Request, request fosite.AccessRequester) error {
// grant_type REQUIRED.
// Value MUST be set to "refresh_token".
if !request.GetGrantTypes().Exact("refresh_token") {
return errors.Wrap(fosite.ErrUnknownRequest, "")
}
if !request.GetClient().GetGrantTypes().Has("refresh_token") {
return errors.Wrap(fosite.ErrInvalidGrant, "The client is not allowed to use grant type refresh_token")
}
refresh := req.PostForm.Get("refresh_token")
signature := c.RefreshTokenStrategy.RefreshTokenSignature(refresh)
originalRequest, err := c.RefreshTokenGrantStorage.GetRefreshTokenSession(ctx, signature, request.GetSession())
if errors.Cause(err) == fosite.ErrNotFound {
return errors.Wrap(fosite.ErrInvalidRequest, err.Error())
} else if err != nil {
return errors.Wrap(fosite.ErrServerError, err.Error())
}
if !originalRequest.GetGrantedScopes().Has("offline") {
return errors.Wrap(fosite.ErrScopeNotGranted, "The client is not allowed to use grant type refresh_token")
}
// The authorization server MUST ... validate the refresh token.
if err := c.RefreshTokenStrategy.ValidateRefreshToken(ctx, request, refresh); err != nil {
return errors.Wrap(fosite.ErrInvalidRequest, err.Error())
}
// The authorization server MUST ... and ensure that the refresh token was issued to the authenticated client
if originalRequest.GetClient().GetID() != request.GetClient().GetID() {
return errors.Wrap(fosite.ErrInvalidRequest, "Client ID mismatch")
}
request.SetSession(originalRequest.GetSession())
request.SetRequestedScopes(originalRequest.GetRequestedScopes())
for _, scope := range originalRequest.GetGrantedScopes() {
request.GrantScope(scope)
}
request.GetSession().SetExpiresAt(fosite.AccessToken, time.Now().Add(c.AccessTokenLifespan))
return nil
}