[GH-ISSUE #391] RenewAccessToken throwing AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext #247

Closed
opened 2026-03-03 16:47:03 +03:00 by kerem · 6 comments
Owner

Originally created by @sheetal-hemrom on GitHub (Jul 7, 2017).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/391

Description:

AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext
while calling renewAccessToken.

The authorize is successful and I save the refreshToken from credentials in my UserDefaults.

        oauthswift.renewAccessToken(withRefreshToken: refreshToken, headers : nil ,success: { (credential, response, parameters) in
            print(credential.oauthToken)
            print(credential.oauthRefreshToken)
            completionHandler(true, credential.oauthToken,credential.oauthRefreshToken)
        } , failure: { (error) in
            print(error.localizedDescription)
            completionHandler(false, nil,nil)
        })

OAuth Provider (Twitter, Github, ..):

  • PCF

OAuth Version:

  • Version 1
  • Version 2

OS (Please fill the version) :

  • iOS :
  • OSX :
  • TVOS :
  • WatchOS :

Installation method:

  • Carthage
  • CocoaPods
  • Manually

Library version:

  • head
  • v1.0.0
  • v0.6
  • v1.1.1

Xcode version:

  • 8.0 (Swift 3.0)
  • 8.0 (Swift 2.3)
  • 7.3.1
  • other: (Please fill in the version you are using.)
  • objective c
Originally created by @sheetal-hemrom on GitHub (Jul 7, 2017). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/391 ### Description: AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext while calling renewAccessToken. The authorize is successful and I save the refreshToken from credentials in my UserDefaults. ``` oauthswift.renewAccessToken(withRefreshToken: refreshToken, headers : nil ,success: { (credential, response, parameters) in print(credential.oauthToken) print(credential.oauthRefreshToken) completionHandler(true, credential.oauthToken,credential.oauthRefreshToken) } , failure: { (error) in print(error.localizedDescription) completionHandler(false, nil,nil) }) ``` ### OAuth Provider (Twitter, Github, ..): - PCF ### OAuth Version: - [ ] Version 1 - [X] Version 2 ### OS (Please fill the version) : - [x] iOS : - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [ ] Carthage - [x] CocoaPods - [ ] Manually ### Library version: - [ ] head - [ ] v1.0.0 - [ ] v0.6 - [x] v1.1.1 ### Xcode version: - [x] 8.0 (Swift 3.0) - [ ] 8.0 (Swift 2.3) - [ ] 7.3.1 - [ ] other: (Please fill in the version you are using.) - [ ] objective c
kerem closed this issue 2026-03-03 16:47:03 +03:00
Author
Owner

@phimage commented on GitHub (Jul 7, 2017):

you remove "OAuth Provider" from issue template
the main information I need to help you

Did you try to connect to a server that use spring?

<!-- gh-comment-id:313730949 --> @phimage commented on GitHub (Jul 7, 2017): you remove "OAuth Provider" from issue template the main information I need to help you Did you try to connect to a server that use spring?
Author
Owner

@sheetal-hemrom commented on GitHub (Jul 7, 2017):

@phimage Hi Eric I have bind an application hosted on PCF with their SSO service instance.

<!-- gh-comment-id:313744508 --> @sheetal-hemrom commented on GitHub (Jul 7, 2017): @phimage Hi Eric I have bind an application hosted on PCF with their SSO service instance.
Author
Owner

@phimage commented on GitHub (Jul 7, 2017):

Hi, the normal authentification work well? or only renew failed?

I found in spring (java) the message AbstractSecurityInterceptor.authenticationNotFound=An Authentication object was not found in the SecurityContext

maybe some configuration must be done in server
I don`t think this is an OauthSwift issue

<!-- gh-comment-id:313750117 --> @phimage commented on GitHub (Jul 7, 2017): Hi, the normal authentification work well? or only renew failed? I found in spring (java) the message `AbstractSecurityInterceptor.authenticationNotFound=An Authentication object was not found in the SecurityContext` maybe some configuration must be done in server I don`t think this is an OauthSwift issue
Author
Owner

@sheetal-hemrom commented on GitHub (Jul 7, 2017):

Hi. The normal authentication (authorize) do work and so I am able to receive token and refresh token at first place. But while renewing if I receive the issue which exactly does the same flow just different POST parameters (as I debugged) . I think it should not be a PCF issue but OAuth might be following different configuration for authorize and renew calls

<!-- gh-comment-id:313754671 --> @sheetal-hemrom commented on GitHub (Jul 7, 2017): Hi. The normal authentication (authorize) do work and so I am able to receive token and refresh token at first place. But while renewing if I receive the issue which exactly does the same flow just different POST parameters (as I debugged) . I think it should not be a PCF issue but OAuth might be following different configuration for authorize and renew calls
Author
Owner

@sheetal-hemrom commented on GitHub (Jul 7, 2017):

I will also check with my server if that is the case

<!-- gh-comment-id:313758981 --> @sheetal-hemrom commented on GitHub (Jul 7, 2017): I will also check with my server if that is the case
Author
Owner

@sheetal-hemrom commented on GitHub (Jul 7, 2017):

@phimage So I found out that renew works after sometime and not when I just log in . While I was trying renew I was trying to renew just under the completion block of authorize. When I saved the refresh token for later and hit renew it worked. It might be a PivotalCloudFoundary issue but I got a hint in this answer here

<!-- gh-comment-id:313776842 --> @sheetal-hemrom commented on GitHub (Jul 7, 2017): @phimage So I found out that renew works after sometime and not when I just log in . While I was trying renew I was trying to renew just under the completion block of authorize. When I saved the refresh token for later and hit renew it worked. It might be a PivotalCloudFoundary issue but I got a hint in this answer [here](https://stackoverflow.com/a/16727172/898057)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#247
No description provided.