Skip to content

Commit

Permalink
Merge pull request #463 from okta/fix-empty-nonce-for-dpop
Browse files Browse the repository at this point in the history
fix empty nonce for dpop
  • Loading branch information
duytiennguyen-okta authored Jun 4, 2024
2 parents 90b60d8 + 610231f commit 6739ea3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
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 != "" {
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

0 comments on commit 6739ea3

Please sign in to comment.