[GH-ISSUE #175] Nothing passed back on redirect #105

Closed
opened 2026-03-03 16:45:42 +03:00 by kerem · 10 comments
Owner

Originally created by @amruss on GitHub (Jan 22, 2016).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/175

Sorry ahead of time I'm new to IOS development.

Trying to connect to the Fitbit API and it authenticates fine but when it redirects back to my app nothing is passed back, or rather the code inside the closure never executes. Anyone know what I'm doing wrong?

oauthswift.authorizeWithCallbackURL( NSURL(string: "FitAlarmHelper://")!, scope: "profile", state: state, success: {
credential, response, parameters in
self.showTokenAlert(serviceParameters["name"], credential: credential)
print("done")
self.testFitbit2(oauthswift)
}, failure: { error in
print("error")
print(error.localizedDescription)
})

Originally created by @amruss on GitHub (Jan 22, 2016). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/175 Sorry ahead of time I'm new to IOS development. Trying to connect to the Fitbit API and it authenticates fine but when it redirects back to my app nothing is passed back, or rather the code inside the closure never executes. Anyone know what I'm doing wrong? oauthswift.authorizeWithCallbackURL( NSURL(string: "FitAlarmHelper://")!, scope: "profile", state: state, success: { credential, response, parameters in self.showTokenAlert(serviceParameters["name"], credential: credential) print("done") self.testFitbit2(oauthswift) }, failure: { error in print("error") print(error.localizedDescription) })
kerem 2026-03-03 16:45:42 +03:00
Author
Owner

@phimage commented on GitHub (Jan 22, 2016):

Maybe the callback URL need a path to work
FitAlarmHelper://oauth

And just to be sure

  • did application url scheme is configured ?
  • did OAuthSwift.handleOpenURL(..) is called?
<!-- gh-comment-id:173814354 --> @phimage commented on GitHub (Jan 22, 2016): Maybe the callback URL need a path to work FitAlarmHelper://oauth And just to be sure - did application url scheme is configured ? - did OAuthSwift.handleOpenURL(..) is called?
Author
Owner

@amruss commented on GitHub (Jan 22, 2016):

When I change the callback url to FitAlarmHelper://oauth or anything else I get this

screen shot 2016-01-21 at 9 31 24 pm

Done Both of those:
screen shot 2016-01-21 at 9 33 43 pm

screen shot 2016-01-21 at 9 36 06 pm
<!-- gh-comment-id:173817906 --> @amruss commented on GitHub (Jan 22, 2016): When I change the callback url to FitAlarmHelper://oauth or anything else I get this <img width="369" alt="screen shot 2016-01-21 at 9 31 24 pm" src="https://cloud.githubusercontent.com/assets/13264141/12503221/09fccd16-c087-11e5-924a-047a525e8288.png"> Done Both of those: <img width="517" alt="screen shot 2016-01-21 at 9 33 43 pm" src="https://cloud.githubusercontent.com/assets/13264141/12503222/0f724e9c-c087-11e5-9516-5b930e3a2c17.png"> <img width="382" alt="screen shot 2016-01-21 at 9 36 06 pm" src="https://cloud.githubusercontent.com/assets/13264141/12503225/1419a1f2-c087-11e5-80d1-46bd71c1b0f7.png">
Author
Owner

@phimage commented on GitHub (Jan 22, 2016):

Did you define an application into https://dev.fitbit.com/apps/
and defined the callback url white list

mine is oauth-swift://oauth-callback/fitbit2 for the demo app

maybe remove uppercase also

<!-- gh-comment-id:173819240 --> @phimage commented on GitHub (Jan 22, 2016): Did you define an application into https://dev.fitbit.com/apps/ and defined the callback url white list mine is oauth-swift://oauth-callback/fitbit2 for the demo app maybe remove uppercase also
Author
Owner

@amruss commented on GitHub (Jan 22, 2016):

Yes I did!
screen shot 2016-01-21 at 9 47 21 pm

<!-- gh-comment-id:173819474 --> @amruss commented on GitHub (Jan 22, 2016): Yes I did! <img width="385" alt="screen shot 2016-01-21 at 9 47 21 pm" src="https://cloud.githubusercontent.com/assets/13264141/12503374/9e94c68a-c088-11e5-8565-e4c02b475a7b.png">
Author
Owner

@phimage commented on GitHub (Jan 22, 2016):

Set FitAlarmHelper://oauth if you use FitAlarmHelper://oauth
Set FitAlarmHelper://oauth-callback is you use FitAlarmHelper://oauth-allback
Fitbit need to match the full URL

<!-- gh-comment-id:173819559 --> @phimage commented on GitHub (Jan 22, 2016): Set FitAlarmHelper://oauth if you use FitAlarmHelper://oauth Set FitAlarmHelper://oauth-callback is you use FitAlarmHelper://oauth-allback Fitbit need to match the full URL
Author
Owner

@amruss commented on GitHub (Jan 22, 2016):

Hmm I did that, and i don't get an error when it redirects back to my app. But, it still doesn't execute the code in the closure. It acts just like when I used FitAlarmHelper://

<!-- gh-comment-id:173820769 --> @amruss commented on GitHub (Jan 22, 2016): Hmm I did that, and i don't get an error when it redirects back to my app. But, it still doesn't execute the code in the closure. It acts just like when I used FitAlarmHelper://
Author
Owner

@phimage commented on GitHub (Jan 22, 2016):

Have you see OAuthSwift.handleOpenURL called? using a breakpoint into func application(application: UIApplication!, openURL url: NSURL!, sourceApplication: String!, annotation: AnyObject!)

Is it your code ?
https://cloud.githubusercontent.com/assets/13264141/12503225/1419a1f2-c087-11e5-80d1-46bd71c1b0f7.png
This code is for FitAlarmHelper://oauth-callback only

<!-- gh-comment-id:173821111 --> @phimage commented on GitHub (Jan 22, 2016): Have you see `OAuthSwift.handleOpenURL` called? using a breakpoint into `func application(application: UIApplication!, openURL url: NSURL!, sourceApplication: String!, annotation: AnyObject!)` Is it your code ? https://cloud.githubusercontent.com/assets/13264141/12503225/1419a1f2-c087-11e5-80d1-46bd71c1b0f7.png This code is for FitAlarmHelper://oauth-callback only
Author
Owner

@amruss commented on GitHub (Jan 22, 2016):

Okay it doesn't look like handleOpenURL is ever called
I took away the if statement to see if it was blocking it but it still wasn't called. Any idea what I'm doing wrong?

<!-- gh-comment-id:173822945 --> @amruss commented on GitHub (Jan 22, 2016): Okay it doesn't look like handleOpenURL is ever called I took away the if statement to see if it was blocking it but it still wasn't called. Any idea what I'm doing wrong?
Author
Owner

@phimage commented on GitHub (Jan 22, 2016):

hummm

Did you use a authorize_url_handler ? if you make iOS9 dev you can try the SFSafariViewController

I just updated readme ae4c47d4a7 application(application: method signature, without any ! because have a wrong method signature by copying readme could be the issue

Maybe iOS9 must also declare URL scheme into LSApplicationQueriesSchemes, I expect not...

Declare targeted applications URL schemes in iOS9

In iOS 9 you must whitelist any URL schemes your app wants to query in Info.plist under the LSApplicationQueriesSchemes key (an array of strings)
xcode-white-list

<!-- gh-comment-id:173824565 --> @phimage commented on GitHub (Jan 22, 2016): hummm Did you use a `authorize_url_handler` ? if you make iOS9 dev you can try the `SFSafariViewController` ## I just updated readme ae4c47d4a742b7b10cdbdec1e8766fbd60e87514 `application(application:` method signature, without any `!` because have a wrong method signature by copying readme could be the issue ## Maybe iOS9 must also declare URL scheme into LSApplicationQueriesSchemes, I expect not... #### Declare targeted applications URL schemes in iOS9 In iOS 9 you must whitelist any URL schemes your app wants to query in Info.plist under the _LSApplicationQueriesSchemes_ key (an array of strings) ![xcode-white-list](http://useyourloaf.com/assets/images/2015/2015-09-06-001.png)
Author
Owner

@amruss commented on GitHub (Jan 23, 2016):

Thank you! I changed my AppDelegate and it fixed the issue. Appreciate the help!

<!-- gh-comment-id:174100335 --> @amruss commented on GitHub (Jan 23, 2016): Thank you! I changed my AppDelegate and it fixed the issue. Appreciate the help!
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#105
No description provided.