Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle oauth_verifier manually ('oob' callback URL) #678

Open
zisoft opened this issue Oct 7, 2021 · 1 comment
Open

How to handle oauth_verifier manually ('oob' callback URL) #678

zisoft opened this issue Oct 7, 2021 · 1 comment

Comments

@zisoft
Copy link

zisoft commented Oct 7, 2021

I'm developing a plugin for a MacOS application which will use the Flickr API.
Because this is only a plugin I cannot provide an own URL scheme for the callback so according to the OAuth1 spec I set 'oob' (out-of-band) for the callback URL.

So I implemented the following steps:

oauthswift = OAuth1Swift(
    consumerKey:    "********",
    consumerSecret: "********",
    requestTokenUrl: "https://www.flickr.com/services/oauth/request_token",
    authorizeUrl:    "https://www.flickr.com/services/oauth/authorize",
    accessTokenUrl:  "https://www.flickr.com/services/oauth/access_token"
)

// authorize
let handle = oauthswift.authorize(
    withCallbackURL: "oob") { result in
    switch result {
    case .success(let (credential, response, parameters)):
      print(credential.oauthToken)
      print(credential.oauthTokenSecret)
      print(parameters["user_id"])
      // Do your request
    case .failure(let error):
      print(error.localizedDescription)
    }             
}

This works as expected, the Flickr authorize page is opened in the browser and after approving permissions I get the verifier code displayed on that page. With this verifier I now need to call the accessTokenUrl.

I cannot figure out how to manually set the oauth_verifier in client.credentials because it is readonly.

EDIT:
I have declared open the OAuthSwiftCredential.oauthVerifier property as well as the OAuth1Swift.postOAuthAccessTokenWithRequestToken method. Now I can manually set the oauth_verifier value after authorize and then call the accessTokenUrl. But I'm curious to know if I'm the only one who uses this workflow?

@sk-chanch
Copy link


let header = oauthswift?.client.credential.makeHeaders("https://xxxx.com/access_token",
                                                               method: .POST,
                                                               parameters: `["oauth_verifier":"*************"])`
        
        
        
        oauthswift?.client.post("https://xxxx.com/access_token",
                                headers: header)
        {[weak self] result in
            switch result {
            case .success(let response):
                print(response)
            case .failure(let error):
                print(error)
                
            }
        }


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants