Skip to content

Commit

Permalink
Optionally add callback URL to authorize URL (oauth 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
phimage committed Jun 4, 2017
1 parent b40a9d5 commit 76c7873
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions Sources/OAuth1Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import Foundation

open class OAuth1Swift: OAuthSwift {

// If your oauth provider doesn't provide `oauth_verifier`
/// If your oauth provider doesn't provide `oauth_verifier`
// set this value to true (default: false)
open var allowMissingOAuthVerifier: Bool = false

/// Optionally add callback URL to authorize Url (default: false)
open var addCallbackURLToAuthorizeURL: Bool = false

var consumerKey: String
var consumerSecret: String
var requestTokenUrl: String
Expand Down Expand Up @@ -93,12 +96,21 @@ open class OAuth1Swift: OAuthSwift {
}
}
// 2. Authorize
let urlString = self.authorizeUrl + (self.authorizeUrl.contains("?") ? "&" : "?")
if let token = credential.oauthToken.urlQueryEncoded, let queryURL = URL(string: urlString + "oauth_token=\(token)") {
self.authorizeURLHandler.handle(queryURL)
if let token = credential.oauthToken.urlQueryEncoded {
var urlString = self.authorizeUrl + (self.authorizeUrl.contains("?") ? "&" : "?")
urlString += "oauth_token=\(token)"
if self.addCallbackURLToAuthorizeURL {
urlString += "&oauth_callback=\(callbackURL.absoluteString)"
}
if let queryURL = URL(string: urlString) {
self.authorizeURLHandler.handle(queryURL)
} else {
failure?(OAuthSwiftError.encodingError(urlString: urlString))
}
} else {
failure?(OAuthSwiftError.encodingError(urlString: urlString))
failure?(OAuthSwiftError.encodingError(urlString: credential.oauthToken)) //TODO specific error
}

}, failure: failure)

return self
Expand Down

0 comments on commit 76c7873

Please sign in to comment.