coinbase / coinbase-ios-sdk

Integrate bitcoin into your iOS application with Coinbase
https://www.coinbase.com/
Apache License 2.0
171 stars 67 forks source link

Coinbase OAuth2 authorize getting response error "invalid_grant" #37

Closed hsmith825 closed 6 years ago

hsmith825 commented 6 years ago

I have followed the directions outlined here (and shown below). The Coinable dialog opens and I link my account. I get an email indicated my account is linked to my app. However,, the response I get in the AppDelegate is: Error Domain=CoinbaseErrorDomain Code=0 "invalid_grant" UserInfo={NSLocalizedDescription=invalid_grant, NSLocalizedRecoverySuggestion=}

A code sniper is as follows: ViewController.swift CoinbaseOAuth.startAuthentication(withClientId: "****", scope: "user balance", redirectUri: "com.example.flick.Auth.coinbase-oauth://coinbase-oauth", meta: nil)

AppDelegate func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { if url.scheme == "com.example.flick.auth.coinbase-oauth" { CoinbaseOAuth.finishAuthentication(for: url, clientId: "*****", clientSecret: "**", completion: { (result, error) in if error != nil { // Could not authenticate. print("AppDelegate, Could not authenticate, error = (error!)") } else { // Tokens successfully obtained! // Do something with them (store them, etc.) if let result = result as? [String : AnyObject] { if let accessToken = result["access_token"] as? String { let apiClient = Coinbase(oAuthAccessToken: accessToken) print("AppDelegate, accessToken = (accessToken)") print("AppDelegate, OAuthAccessToken = (apiClient!)") } } // Note that you should also store 'expire_in' and refresh the token using CoinbaseOAuth.getOAuthTokensForRefreshToken() when it expires } }) return true } else { return false } }

If you have questions, please contact me.

Thanks for your help! Howard

hsmith825 commented 6 years ago

This is the addition to the problem above.

What I expect to get are the access_token and oAuthAccessToken. I did not get either token.

Any ideas are appreciated! Thanks! Howard

MaeseppTarvo commented 6 years ago

How did you resolve?

hsmith825 commented 6 years ago

I had a problem with my redirect URL.

On Mar 18, 2018, at 1:06 AM, Tarvo notifications@github.com wrote:

How did you resolve?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/coinbase/coinbase-ios-sdk/issues/37#issuecomment-373979976, or mute the thread https://github.com/notifications/unsubscribe-auth/ABVFjGwmbG6SzCpxqJkhexbDBwf4MWDgks5tfhWGgaJpZM4SGOPZ.

MaeseppTarvo commented 6 years ago

@hsmith825 Can you be more specific? I have the exact same problem.

hsmith825 commented 6 years ago

I am not exactly certain but as I recall, I had an inconsistency between the URL indirect specified in my Coinable dashboard, the Info.plist URL types, and CoinbaseOAuth.startAuthentication(withClientId. One thing key to my getting the APIs to work, I placed CoinbaseOAuth.startAuthentication(withClientId: in override func viewWillAppear of ViewController.

Hope this helps. Howard

On Mar 19, 2018, at 2:15 PM, Tarvo notifications@github.com wrote:

@hsmith825 https://github.com/hsmith825 Can you be more specific? I have the exact same problem.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/coinbase/coinbase-ios-sdk/issues/37#issuecomment-374380210, or mute the thread https://github.com/notifications/unsubscribe-auth/ABVFjAfHAZu6rfN5n-J2L1R1zZ-2BAV6ks5tgB_ZgaJpZM4SGOPZ.

Fonta1n3 commented 6 years ago

I had the same issue, turns out it was that my URI had some capital letters in it which needed to be changed to lower case.

it was the portion of my bundle id in the uri.

For example the "com.CoinbaseApp.Version" part of my URI needed to be changed to "com.coinbaseapp.version" in both my app delegate CoinbaseOAuth.finishAuthentication and the view controller where i call CoinbaseOAuth.startAuthentication.

Hope that helps someone.