@@ -161,13 +161,13 @@ func NewPrivateKeyAuth(config PrivateKeyAuthConfig) *PrivateKeyAuth {
161
161
162
162
func (a *PrivateKeyAuth) Authorize(method, URL string) error {
163
163
accessToken, hasToken := a.tokenCache.Get(AccessTokenCacheKey)
164
- if hasToken {
164
+ if hasToken && accessToken != " " {
165
165
accessTokenWithTokenType := accessToken.(string)
166
166
a.req.Header.Add(" Authorization" , accessTokenWithTokenType)
167
167
nonce, hasNonce := a.tokenCache.Get(DpopAccessTokenNonce)
168
- if hasNonce {
168
+ if hasNonce && nonce != " " {
169
169
privateKey, ok := a.tokenCache.Get(DpopAccessTokenPrivateKey)
170
- if ok {
170
+ if ok && privateKey != nil {
171
171
res := strings.Split(accessTokenWithTokenType, " " )
172
172
if len(res) != 2 {
173
173
return errors.New(" Unidentified access token" )
@@ -178,6 +178,8 @@ func (a *PrivateKeyAuth) Authorize(method, URL string) error {
178
178
}
179
179
a.req.Header.Set("Dpop", dpopJWT)
180
180
a.req.Header.Set("x-okta-user-agent-extended", "isDPoP:true")
181
+ } else {
182
+ return errors.New(" Using Dpop but signing key not found" )
181
183
}
182
184
}
183
185
} else {
@@ -259,13 +261,13 @@ func NewJWTAuth(config JWTAuthConfig) *JWTAuth {
259
261
260
262
func (a *JWTAuth) Authorize(method, URL string) error {
261
263
accessToken, hasToken := a.tokenCache.Get(AccessTokenCacheKey)
262
- if hasToken {
264
+ if hasToken && accessToken != " " {
263
265
accessTokenWithTokenType := accessToken.(string)
264
266
a.req.Header.Add(" Authorization" , accessTokenWithTokenType)
265
267
nonce, hasNonce := a.tokenCache.Get(DpopAccessTokenNonce)
266
- if hasNonce {
268
+ if hasNonce && nonce != " " {
267
269
privateKey, ok := a.tokenCache.Get(DpopAccessTokenPrivateKey)
268
- if ok {
270
+ if ok && privateKey != nil {
269
271
res := strings.Split(accessTokenWithTokenType, " " )
270
272
if len(res) != 2 {
271
273
return errors.New(" Unidentified access token" )
@@ -276,6 +278,8 @@ func (a *JWTAuth) Authorize(method, URL string) error {
276
278
}
277
279
a.req.Header.Set("Dpop", dpopJWT)
278
280
a.req.Header.Set("x-okta-user-agent-extended", "isDPoP:true")
281
+ } else {
282
+ return errors.New(" Using Dpop but signing key not found" )
279
283
}
280
284
}
281
285
} else {
0 commit comments