Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add identity ID to password grant extra claims #831

Merged
merged 7 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
hperl marked this conversation as resolved.
Show resolved Hide resolved
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
hperl marked this conversation as resolved.
Show resolved Hide resolved
}
}

// 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)
hperl marked this conversation as resolved.
Show resolved Hide resolved
AccessTokenStorage
RefreshTokenStorage
}
11 changes: 4 additions & 7 deletions internal/oauth2_owner_storage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading