[GH-ISSUE #515] Setting Content-Type header for OAuth1 #337

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

Originally created by @csauvage on GitHub (Feb 17, 2019).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/515

Description:

Issue while authorizing

OAuth Provider? (Twitter, Github, ..):

Clever-cloud
📖Docs : https://www.clever-cloud.com/doc/api/

OAuth Version:

  • Version 1

OS (Please fill the version) :

  • macOS :

Installation method:

  • Carthage

Library version:

  • v1.2 (Swift 4.0)

Xcode version:

  • other: 10.1

Issue


let oAuthConsumer = OAuth1Swift(
            consumerKey: consumerKey,
            consumerSecret: consumerSecret,
            requestTokenUrl: CleverAPIEndpoint.oAuthRequestToken.url(),
            authorizeUrl: CleverAPIEndpoint.oAuthAuthorize.url(),
            accessTokenUrl: CleverAPIEndpoint.oAuthAccessToken.url()
        );
        
        oAuthConsumer.authorize(
            withCallbackURL: "clever-mac://app/login",
            success: { (credentials, response, parameters) in
                print("success");
        }) { (error) in
            print(error)
            print(error.localizedDescription)
        }


I got an error 500 while authorizing

Solving tip
It seems that it's linked to the header Content-Type of the requestTokenUrl request. It doesn't have the application/x-www-form-urlencoded required value. Where to set this header ?

Moreover @phimage : Analysing the request on Charles, it seems that the body of the resquest is empty

image

Any help will be appreciated ! Stucking around for a while now :/

Originally created by @csauvage on GitHub (Feb 17, 2019). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/515 ### Description: Issue while authorizing ### OAuth Provider? (Twitter, Github, ..): [Clever-cloud](https://clever-cloud.com) 📖Docs : [https://www.clever-cloud.com/doc/api/](https://www.clever-cloud.com/doc/api/) ### OAuth Version: - [x] Version 1 ### OS (Please fill the version) : - [x] macOS : ### Installation method: - [x] Carthage ### Library version: - [x] v1.2 (Swift 4.0) ### Xcode version: - [x] other: 10.1 *Issue* ```swift let oAuthConsumer = OAuth1Swift( consumerKey: consumerKey, consumerSecret: consumerSecret, requestTokenUrl: CleverAPIEndpoint.oAuthRequestToken.url(), authorizeUrl: CleverAPIEndpoint.oAuthAuthorize.url(), accessTokenUrl: CleverAPIEndpoint.oAuthAccessToken.url() ); oAuthConsumer.authorize( withCallbackURL: "clever-mac://app/login", success: { (credentials, response, parameters) in print("success"); }) { (error) in print(error) print(error.localizedDescription) } ``` I got an error 500 while authorizing *Solving tip* It seems that it's linked to the header `Content-Type` of the `requestTokenUrl` request. It doesn't have the `application/x-www-form-urlencoded` required value. Where to set this header ? Moreover @phimage : Analysing the request on Charles, it seems that the **body of the resquest** is empty ![image](https://user-images.githubusercontent.com/3155160/52975310-05addc00-3393-11e9-88c5-d10479f89331.png) Any help will be appreciated ! Stucking around for a while now :/
kerem closed this issue 2026-03-03 16:47:50 +03:00
Author
Owner

@phimage commented on GitHub (Feb 18, 2019):

There is an header optional parameter
But for Content-type I never tested it

<!-- gh-comment-id:464592152 --> @phimage commented on GitHub (Feb 18, 2019): There is an header optional parameter But for Content-type I never tested it
Author
Owner

@csauvage commented on GitHub (Feb 18, 2019):

      
        oauthSwift = OAuth1Swift(
            consumerKey:    "GQldQj8WtdMTXmifxpyAQeOjr5v9UX",
            consumerSecret: "hZsfW3D6FPZK9qtV81wNsh9HrFJvE9",
            requestTokenUrl: "\(baseUrl)/oauth/request_token_query",
            authorizeUrl:    "\(baseUrl)/oauth/authorize",
            accessTokenUrl:  "\(baseUrl)/oauth/access_token",
            header: ["Content-Type": "application/x-www-form-urlencoded"]
        );

Triggers a compilation error :

Cannot invoke initializer for type 'OAuth1Swift' with an argument list of type '(consumerKey: String, consumerSecret: String, requestTokenUrl: String, authorizeUrl: String, accessTokenUrl: String, header: [String : String])'

@phimage there's no such signature in https://github.com/OAuthSwift/OAuthSwift/blob/master/Sources/OAuth1Swift.swift source file.
Thanks in advance for your help.

<!-- gh-comment-id:464771639 --> @csauvage commented on GitHub (Feb 18, 2019): ```swift oauthSwift = OAuth1Swift( consumerKey: "GQldQj8WtdMTXmifxpyAQeOjr5v9UX", consumerSecret: "hZsfW3D6FPZK9qtV81wNsh9HrFJvE9", requestTokenUrl: "\(baseUrl)/oauth/request_token_query", authorizeUrl: "\(baseUrl)/oauth/authorize", accessTokenUrl: "\(baseUrl)/oauth/access_token", header: ["Content-Type": "application/x-www-form-urlencoded"] ); ``` Triggers a compilation error : > Cannot invoke initializer for type 'OAuth1Swift' with an argument list of type '(consumerKey: String, consumerSecret: String, requestTokenUrl: String, authorizeUrl: String, accessTokenUrl: String, header: [String : String])' @phimage there's no such signature in [https://github.com/OAuthSwift/OAuthSwift/blob/master/Sources/OAuth1Swift.swift](https://github.com/OAuthSwift/OAuthSwift/blob/master/Sources/OAuth1Swift.swift) source file. Thanks in advance for your help.
Author
Owner

@phimage commented on GitHub (Feb 19, 2019):

there is no network call when you initialize the object, you must use authorize
maybe there is nothing for oauth1 because this is not standard

for oauth 2 there is an header parameters https://github.com/OAuthSwift/OAuthSwift/blob/master/Sources/OAuth2Swift.swift#L83
for a PR could be done to add it

<!-- gh-comment-id:465021977 --> @phimage commented on GitHub (Feb 19, 2019): there is no network call when you initialize the object, you must use authorize maybe there is nothing for oauth1 because this is not standard for oauth 2 there is an header parameters https://github.com/OAuthSwift/OAuthSwift/blob/master/Sources/OAuth2Swift.swift#L83 for a PR could be done to add it
Author
Owner

@csauvage commented on GitHub (Feb 20, 2019):

Yeah, of course, I mean doing this don't produce a request body

        oAuthConsumer.authorize(
            withCallbackURL: "myCustomURL://",
            success: { (credentials, response, parameters) in
                print("success");
        }) { (error) in
            print(error)
            print(error.localizedDescription)
        }

And I'm talking of oAuth, will see if I can PR

<!-- gh-comment-id:465621618 --> @csauvage commented on GitHub (Feb 20, 2019): Yeah, of course, I mean doing this don't produce a request body ``` oAuthConsumer.authorize( withCallbackURL: "myCustomURL://", success: { (credentials, response, parameters) in print("success"); }) { (error) in print(error) print(error.localizedDescription) } ``` And I'm talking of oAuth, will see if I can PR
Author
Owner

@csauvage commented on GitHub (Feb 22, 2019):

Made #517 to fix the last method with header. It didn’t goes though CI. I guess you haven’t exposed Danger API Key.

<!-- gh-comment-id:466312002 --> @csauvage commented on GitHub (Feb 22, 2019): Made #517 to fix the last method with header. It didn’t goes though CI. I guess you haven’t exposed Danger API Key.
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#337
No description provided.