forked from ory/fosite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handler/openid: refresh token handler for oidc (ory#193)
closes ory#181
- Loading branch information
1 parent
3de2033
commit 02948d9
Showing
7 changed files
with
131 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package openid | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ory/fosite" | ||
"github.com/pkg/errors" | ||
"time" | ||
) | ||
|
||
type OpenIDConnectRefreshHandler struct { | ||
*IDTokenHandleHelper | ||
} | ||
|
||
func (c *OpenIDConnectRefreshHandler) HandleTokenEndpointRequest(ctx context.Context, request fosite.AccessRequester) error { | ||
if !request.GetGrantTypes().Exact("refresh_token") { | ||
return errors.WithStack(fosite.ErrUnknownRequest) | ||
} | ||
|
||
if !request.GetGrantedScopes().Has("openid") { | ||
return errors.WithStack(fosite.ErrUnknownRequest) | ||
} | ||
|
||
sess, ok := request.GetSession().(Session) | ||
if !ok { | ||
return errors.New("Failed to generate id token because session must be of type fosite/handler/openid.Session") | ||
} | ||
|
||
// We need to reset the expires at value | ||
sess.IDTokenClaims().ExpiresAt = time.Time{} | ||
return nil | ||
} | ||
|
||
func (c *OpenIDConnectRefreshHandler) PopulateTokenEndpointResponse(ctx context.Context, requester fosite.AccessRequester, responder fosite.AccessResponder) error { | ||
if !requester.GetGrantTypes().Exact("refresh_token") { | ||
return errors.WithStack(fosite.ErrUnknownRequest) | ||
} | ||
|
||
if !requester.GetGrantedScopes().Has("openid") { | ||
return errors.WithStack(fosite.ErrUnknownRequest) | ||
} | ||
|
||
return c.IssueExplicitIDToken(ctx, requester, responder) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package integration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters