[GH-ISSUE #150] HTTP Response doesn't always have an 'access_token' key. #93

Closed
opened 2026-03-03 16:45:36 +03:00 by kerem · 4 comments
Owner

Originally created by @SokichiFujita on GitHub (Nov 26, 2015).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/150

The following error occurred in the GitHub authorization flow.

OAuth2Swift.swift
OAuthSwift

In regard to this response, it has only "error_description", "error" and "error_uri" keys. There are no 'access_token' key. Please consider to validate whether it has "access_token" key or not. if let statement may be a solution.

Originally created by @SokichiFujita on GitHub (Nov 26, 2015). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/150 The following error occurred in the GitHub authorization flow. [OAuth2Swift.swift](https://github.com/dongri/OAuthSwift/blob/master/OAuthSwift/OAuth2Swift.swift) ![OAuthSwift](https://cloud.githubusercontent.com/assets/15647722/11421705/c44dae36-9479-11e5-9314-64cc66645257.png) In regard to this response, it has only `"error_description"`, `"error"` and `"error_uri"` keys. There are no 'access_token' key. Please consider to validate whether it has `"access_token"` key or not. `if let` statement may be a solution.
kerem 2026-03-03 16:45:36 +03:00
  • closed this issue
  • added the
    duplicate
    label
Author
Owner

@SokichiFujita commented on GitHub (Nov 26, 2015):

I don't know why GitHub uses status code 200 for this response.

<!-- gh-comment-id:159900615 --> @SokichiFujita commented on GitHub (Nov 26, 2015): I don't know why GitHub uses status code 200 for this response.
Author
Owner

@phimage commented on GitHub (Nov 26, 2015):

Already fixed in master branch and available in next release
as you can see in the link you put into your comment

85dbcddf89

   guard let accessToken = responseParameters["access_token"] as? String else {
                    if let failure = failure {
                        let errorInfo = [NSLocalizedFailureReasonErrorKey: NSLocalizedString("Could not get Access Token", comment: "Due to an error in the OAuth2 process, we couldn't get a valid token.")]
                        failure(error: NSError(domain: OAuthSwiftErrorDomain, code: -1, userInfo: errorInfo))
                    }
                    return
                }

I close and expect a new release soon for you ;)

<!-- gh-comment-id:159901049 --> @phimage commented on GitHub (Nov 26, 2015): Already fixed in master branch and available in next release as you can see in the link you put into your comment 85dbcddf891e9ad3ba321175707990bba3ea8095 ``` swift guard let accessToken = responseParameters["access_token"] as? String else { if let failure = failure { let errorInfo = [NSLocalizedFailureReasonErrorKey: NSLocalizedString("Could not get Access Token", comment: "Due to an error in the OAuth2 process, we couldn't get a valid token.")] failure(error: NSError(domain: OAuthSwiftErrorDomain, code: -1, userInfo: errorInfo)) } return } ``` I close and expect a new release soon for you ;)
Author
Owner

@SokichiFujita commented on GitHub (Nov 26, 2015):

Thank you! I expect the release!

<!-- gh-comment-id:159907713 --> @SokichiFujita commented on GitHub (Nov 26, 2015): Thank you! I expect the release!
Author
Owner

@phimage commented on GitHub (Nov 26, 2015):

どういたしまして

<!-- gh-comment-id:159910444 --> @phimage commented on GitHub (Nov 26, 2015): どういたしまして
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#93
No description provided.