Skip to content

Commit

Permalink
feat: add identity ID to password grant extra claims
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl committed Oct 28, 2024
1 parent 8631deb commit b35b62f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion handler/oauth2/flow_resource_owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ func (c *ResourceOwnerPasswordCredentialsGrantHandler) HandleTokenEndpointReques
password := request.GetRequestForm().Get("password")
if username == "" || password == "" {
return errorsx.WithStack(fosite.ErrInvalidRequest.WithHint("Username or password are missing from the POST body."))
} else if err := c.ResourceOwnerPasswordCredentialsGrantStorage.Authenticate(ctx, username, password); errors.Is(err, fosite.ErrNotFound) {
} else if identityID, err := c.ResourceOwnerPasswordCredentialsGrantStorage.Authenticate(ctx, username, password); errors.Is(err, fosite.ErrNotFound) {
return errorsx.WithStack(fosite.ErrInvalidGrant.WithHint("Unable to authenticate the provided username and password credentials.").WithWrap(err).WithDebug(err.Error()))
} else if err != nil {
return errorsx.WithStack(fosite.ErrServerError.WithWrap(err).WithDebug(err.Error()))
} else {
if sess, ok := request.GetSession().(fosite.ExtraClaimsSession); ok {
sess.GetExtraClaims()["identity_id"] = identityID
}
}

// Credentials must not be passed around, potentially leaking to the database!
Expand Down
2 changes: 1 addition & 1 deletion handler/oauth2/flow_resource_owner_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type ResourceOwnerPasswordCredentialsGrantStorage interface {
Authenticate(ctx context.Context, name string, secret string) error
Authenticate(ctx context.Context, name string, secret string) (string, error)
AccessTokenStorage
RefreshTokenStorage
}

0 comments on commit b35b62f

Please sign in to comment.