[GH-ISSUE #16] JSON Response support #8

Closed
opened 2026-03-03 16:44:44 +03:00 by kerem · 2 comments
Owner

Originally created by @raulriera on GitHub (Jan 12, 2015).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/16

I modified the postOAuthAccessTokenWithRequestTokenByCode method to support JSON responses like Dribbble OAuth implementation

func postOAuthAccessTokenWithRequestTokenByCode(code: String, success: TokenSuccessHandler, failure: FailureHandler?) {
        var parameters = Dictionary<String, AnyObject>()
        parameters["client_id"] = self.consumer_key
        parameters["client_secret"] = self.consumer_secret
        parameters["code"] = code
        parameters["grant_type"] = "authorization_code"

        self.client.post(self.access_token_url!, parameters: parameters, success: {
            data, response in
            let responseString = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil)
            if let parameters:NSDictionary = responseString as? NSDictionary{
                self.client.credential.oauth_token = parameters["access_token"] as String
                success(credential: self.client.credential, response: response)
            }
        }, failure: failure)
    }

I was wondering if you had any ideas on how to integrate this gracefully into the project so the other "normal string" response types is supported as well.

Originally created by @raulriera on GitHub (Jan 12, 2015). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/16 I modified the `postOAuthAccessTokenWithRequestTokenByCode` method to support JSON responses like [Dribbble OAuth implementation](http://developer.dribbble.com/v1/oauth/#redirect-urls) ``` swift func postOAuthAccessTokenWithRequestTokenByCode(code: String, success: TokenSuccessHandler, failure: FailureHandler?) { var parameters = Dictionary<String, AnyObject>() parameters["client_id"] = self.consumer_key parameters["client_secret"] = self.consumer_secret parameters["code"] = code parameters["grant_type"] = "authorization_code" self.client.post(self.access_token_url!, parameters: parameters, success: { data, response in let responseString = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) if let parameters:NSDictionary = responseString as? NSDictionary{ self.client.credential.oauth_token = parameters["access_token"] as String success(credential: self.client.credential, response: response) } }, failure: failure) } ``` I was wondering if you had any ideas on how to integrate this gracefully into the project so the other "normal string" response types is supported as well.
kerem closed this issue 2026-03-03 16:44:45 +03:00
Author
Owner

@dongri commented on GitHub (Jan 13, 2015):

Thank you!

I Fixed postOAuthAccessTokenWithRequestTokenByCode method
https://github.com/dongri/OAuthSwift/blob/master/OAuthSwift/OAuth2Swift.swift#L105-L115

<!-- gh-comment-id:69755086 --> @dongri commented on GitHub (Jan 13, 2015): Thank you! I Fixed postOAuthAccessTokenWithRequestTokenByCode method https://github.com/dongri/OAuthSwift/blob/master/OAuthSwift/OAuth2Swift.swift#L105-L115
Author
Owner

@raulriera commented on GitHub (Jan 13, 2015):

You rock!

<!-- gh-comment-id:69755330 --> @raulriera commented on GitHub (Jan 13, 2015): You rock!
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#8
No description provided.