Skip to content

Commit

Permalink
use public field to block confidential grants
Browse files Browse the repository at this point in the history
  • Loading branch information
jarlah committed Jan 20, 2023
1 parent e0f39b9 commit be5bcc1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion manage/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (m *Manager) GenerateAccessToken(ctx context.Context, gt oauth2.GrantType,
if !cliPass.VerifyPassword(tgr.ClientSecret) {
return nil, errors.ErrInvalidClient
}
} else if cli.IsPublic() == false && len(cli.GetSecret()) > 0 && tgr.ClientSecret != cli.GetSecret() {
} else if len(cli.GetSecret()) > 0 && tgr.ClientSecret != cli.GetSecret() {
return nil, errors.ErrInvalidClient
}
if tgr.RedirectURI != "" {
Expand All @@ -296,6 +296,10 @@ func (m *Manager) GenerateAccessToken(ctx context.Context, gt oauth2.GrantType,
}
}

if gt == oauth2.ClientCredentials && cli.IsPublic() == true {
return nil, errors.ErrInvalidClient
}

if gt == oauth2.AuthorizationCode {
ti, err := m.getAndDelAuthorizationCode(ctx, tgr)
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ func init() {

func clientStore(domain string, public bool) oauth2.ClientStore {
clientStore := store.NewClientStore()
var secret string
if public {
secret = ""
} else {
secret = clientSecret
}
clientStore.Set(clientID, &models.Client{
ID: clientID,
Secret: clientSecret,
Secret: secret,
Domain: domain,
Public: public,
})
Expand Down

0 comments on commit be5bcc1

Please sign in to comment.