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

fix empty nonce for dpop #463

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .generator/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ additionalProperties:
enumClassPrefix: true
generateInterfaces: true
packageName: okta
packageVersion: 4.1.0
packageVersion: 4.1.1
useOneOfDiscriminatorLookup: true
disallowAdditionalPropertiesIfNotPresent: false
files:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33112,9 +33112,7 @@ components:
readOnly: true
detailEntry:
type: object
additionalProperties:
type: object
properties: {}
additionalProperties: true
readOnly: true
displayName:
type: string
Expand Down
16 changes: 10 additions & 6 deletions .generator/templates/client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ func NewPrivateKeyAuth(config PrivateKeyAuthConfig) *PrivateKeyAuth {

func (a *PrivateKeyAuth) Authorize(method, URL string) error {
accessToken, hasToken := a.tokenCache.Get(AccessTokenCacheKey)
if hasToken {
if hasToken && accessToken != "" {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like hasToken/ok checks are excessive with such approach

accessTokenWithTokenType := accessToken.(string)
a.req.Header.Add("Authorization", accessTokenWithTokenType)
nonce, hasNonce := a.tokenCache.Get(DpopAccessTokenNonce)
if hasNonce {
if hasNonce && nonce != "" {
privateKey, ok := a.tokenCache.Get(DpopAccessTokenPrivateKey)
if ok {
if ok && privateKey != nil {
res := strings.Split(accessTokenWithTokenType, " ")
if len(res) != 2 {
return errors.New("Unidentified access token")
Expand All @@ -178,6 +178,8 @@ func (a *PrivateKeyAuth) Authorize(method, URL string) error {
}
a.req.Header.Set("Dpop", dpopJWT)
a.req.Header.Set("x-okta-user-agent-extended", "isDPoP:true")
} else {
return errors.New("Using Dpop but signing key not found")
}
}
} else {
Expand Down Expand Up @@ -259,13 +261,13 @@ func NewJWTAuth(config JWTAuthConfig) *JWTAuth {

func (a *JWTAuth) Authorize(method, URL string) error {
accessToken, hasToken := a.tokenCache.Get(AccessTokenCacheKey)
if hasToken {
if hasToken && accessToken != "" {
accessTokenWithTokenType := accessToken.(string)
a.req.Header.Add("Authorization", accessTokenWithTokenType)
nonce, hasNonce := a.tokenCache.Get(DpopAccessTokenNonce)
if hasNonce {
if hasNonce && nonce != "" {
privateKey, ok := a.tokenCache.Get(DpopAccessTokenPrivateKey)
if ok {
if ok && privateKey != nil {
res := strings.Split(accessTokenWithTokenType, " ")
if len(res) != 2 {
return errors.New("Unidentified access token")
Expand All @@ -276,6 +278,8 @@ func (a *JWTAuth) Authorize(method, URL string) error {
}
a.req.Header.Set("Dpop", dpopJWT)
a.req.Header.Set("x-okta-user-agent-extended", "isDPoP:true")
} else {
return errors.New("Using Dpop but signing key not found")
}
}
} else {
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
Running changelog of releases since `2.0.0-rc.4`

## v4.1.0
- Fix panic issue when using bearer token (#463) Thanks [@duytiennguyen-okta]
- Fix object that does not have additional properties (#463) Thanks [@duytiennguyen-okta]

## v4.1.0
- Add support for dpop (#454) Thanks [@duytiennguyen-okta]
- Fix object that does not have additional properties (#456) Thanks [@duytiennguyen-okta]
Expand Down