[GH-ISSUE #171] "Could not get Access Token" error when one of the values in response is not a string. #102

Closed
opened 2026-03-03 16:45:41 +03:00 by kerem · 1 comment
Owner

Originally created by @valentinvarbanov on GitHub (Jan 14, 2016).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/171

The OAuth2Swift class interprets wrongly the response from HTTP request in method postOAuthAccessTokenWithRequestTokenByCode("OAuth2Swift.swift") when one of the response values is not of type String. In this case on line 123 in file "OAuth2Swift.swift" the if statement returns false even that it should cast successfully the oath token, and the authentication process returns an error at the end.(I had this problem with LinkedIn OAuth2 authentication. The value of another key-value pair was with types [String: Int].)
My solution is inserting another case(line 125) to try to convert non-string object to string like that:

else if var jsonDico = responseJSON as? [String:AnyObject] { 
                for(k, v) in jsonDico {
                    if !(v is String) {
                        jsonDico[k] = "\(v)"
                    }
                }
                responseParameters = jsonDico as! [String:String]
            }
Originally created by @valentinvarbanov on GitHub (Jan 14, 2016). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/171 The OAuth2Swift class interprets wrongly the response from HTTP request in method `postOAuthAccessTokenWithRequestTokenByCode`("OAuth2Swift.swift") when one of the response values is not of type String. In this case on line 123 in file "OAuth2Swift.swift" the if statement returns false even that it should cast successfully the oath token, and the authentication process returns an error at the end.(I had this problem with LinkedIn OAuth2 authentication. The value of another key-value pair was with types `[String: Int]`.) My solution is inserting another case(line 125) to try to convert non-string object to string like that: ``` swift else if var jsonDico = responseJSON as? [String:AnyObject] { for(k, v) in jsonDico { if !(v is String) { jsonDico[k] = "\(v)" } } responseParameters = jsonDico as! [String:String] } ```
kerem closed this issue 2026-03-03 16:45:41 +03:00
Author
Owner

@phimage commented on GitHub (Jan 14, 2016):

did you experiment the issue with current code? (because I have already fixed that in #159 and describe here https://github.com/OAuthSwift/OAuthSwift/releases)
watch your PR diff and see that your code will never be called, the previous if cast with same dictionary type, no more String:String

<!-- gh-comment-id:171563632 --> @phimage commented on GitHub (Jan 14, 2016): did you experiment the issue with current code? (because I have already fixed that in #159 and describe here https://github.com/OAuthSwift/OAuthSwift/releases) watch your PR diff and see that your code will never be called, the previous if cast with same dictionary type, no more String:String
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#102
No description provided.