Skip to content

Commit

Permalink
fix empty nonce for dpop
Browse files Browse the repository at this point in the history
Signed-off-by: Tien Nguyen <duytien.nguyen@okta.com>
  • Loading branch information
duytiennguyen-okta committed Jun 3, 2024
1 parent 90b60d8 commit 9e108e0
Showing 1 changed file with 10 additions and 6 deletions.
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

0 comments on commit 9e108e0

Please sign in to comment.