[GH-ISSUE #227] Parameters converted to String #129

Closed
opened 2026-03-03 16:45:55 +03:00 by kerem · 8 comments
Owner

Originally created by @kajensen on GitHub (May 10, 2016).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/227

I think you should just return the response NSData (or [String: AnyObject]) instead of casting json to a [String: String]. Unless there is a good reason for this?
This is an issue for instagram oauth where the response has user data in a dictionary.

Originally created by @kajensen on GitHub (May 10, 2016). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/227 I think you should just return the response NSData (or [String: AnyObject]) instead of casting json to a [String: String]. Unless there is a good reason for this? This is an issue for instagram oauth where the response has user data in a dictionary.
kerem 2026-03-03 16:45:55 +03:00
Author
Owner

@phimage commented on GitHub (May 10, 2016):

Could you give the lines of code?

maybe

if let jsonDico = responseJSON as? [String:AnyObject] {
responseParameters = jsonDico.map { (key, value) in (key, String(value)) }
}

the cast here is good, but then all object are converted to string...
Have you really an NSData, not an nsdictionary?

<!-- gh-comment-id:218132077 --> @phimage commented on GitHub (May 10, 2016): Could you give the lines of code? maybe if let jsonDico = responseJSON as? [String:AnyObject] { responseParameters = jsonDico.map { (key, value) in (key, String(value)) } } the cast here is good, but then all object are converted to string... Have you really an NSData, not an nsdictionary?
Author
Owner

@kajensen commented on GitHub (May 11, 2016):

Yeah, thats the line i'm talking about. I changed it so parameters is a [String: AnyObject] dictionary in TokenSuccessHandler, and I return the responseJSON (line 190 in Oauth2.swift) instead of the casted parameters used to extract the credentials as strings.

<!-- gh-comment-id:218486811 --> @kajensen commented on GitHub (May 11, 2016): Yeah, thats the line i'm talking about. I changed it so parameters is a [String: AnyObject] dictionary in TokenSuccessHandler, and I return the responseJSON (line 190 in Oauth2.swift) instead of the casted parameters used to extract the credentials as strings.
Author
Owner

@kajensen commented on GitHub (May 11, 2016):

The cast made it nearly impossible to translate it back to a dictionary so this was easier for me.

<!-- gh-comment-id:218487232 --> @kajensen commented on GitHub (May 11, 2016): The cast made it nearly impossible to translate it back to a dictionary so this was easier for me.
Author
Owner

@phimage commented on GitHub (May 11, 2016):

are you able to respond to my question? is it NSData or NSDictionary?
its readable after converting it to string ?(ie is its a json string, its easy a create a dictionary from it)

<!-- gh-comment-id:218488317 --> @phimage commented on GitHub (May 11, 2016): are you able to respond to my question? is it NSData or NSDictionary? its readable after converting it to string ?(ie is its a json string, its easy a create a dictionary from it)
Author
Owner

@kajensen commented on GitHub (May 11, 2016):

its an nsdictionary. its readable as a string, but I tried a few different things and did not find it easy to create a dictionary from it.

<!-- gh-comment-id:218489451 --> @kajensen commented on GitHub (May 11, 2016): its an nsdictionary. its readable as a string, but I tried a few different things and did not find it easy to create a dictionary from it.
Author
Owner

@phimage commented on GitHub (May 11, 2016):

try this from stack over flow if its a json string, maybe not, just a dictionary string representation
(if not json, maybe I will add a way to choose how to cast to string)

func convertStringToDictionary(text: String) -> [String:AnyObject]? {
if let data = text.dataUsingEncoding(NSUTF8StringEncoding) {
do {
let json = try NSJSONSerialization.JSONObjectWithData(data, options: .MutableContainers) as? [String:AnyObject]
return json
} catch {
print("Something went wrong")
}
}
return nil
}

<!-- gh-comment-id:218490258 --> @phimage commented on GitHub (May 11, 2016): try this from stack over flow if its a json string, maybe not, just a dictionary string representation (if not json, maybe I will add a way to choose how to cast to string) func convertStringToDictionary(text: String) -> [String:AnyObject]? { if let data = text.dataUsingEncoding(NSUTF8StringEncoding) { do { let json = try NSJSONSerialization.JSONObjectWithData(data, options: .MutableContainers) as? [String:AnyObject] return json } catch { print("Something went wrong") } } return nil }
Author
Owner

@kajensen commented on GitHub (May 11, 2016):

Yeah I tried that among other things. I guess I just don't understand the rationale for casting it to a string and then forcing a cast back if necessary?

<!-- gh-comment-id:218490864 --> @kajensen commented on GitHub (May 11, 2016): Yeah I tried that among other things. I guess I just don't understand the rationale for casting it to a string and then forcing a cast back if necessary?
Author
Owner

@phimage commented on GitHub (May 11, 2016):

Unfortunately I can change method signature easily without impacting all people which use the library
You could PR anyway, and I will think about it and merge only into a main release

<!-- gh-comment-id:218492710 --> @phimage commented on GitHub (May 11, 2016): Unfortunately I can change method signature easily without impacting all people which use the library You could PR anyway, and I will think about it and merge only into a main release
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#129
No description provided.