mirror of
https://github.com/OAuthSwift/OAuthSwift.git
synced 2026-04-26 12:45:52 +03:00
[GH-ISSUE #300] Support switching to native application for auth #181
Labels
No labels
bug
cocoapod
duplicate
enhancement
feature-request
help wanted
help wanted
invalid
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/OAuthSwift#181
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @mikegray on GitHub (Oct 20, 2016).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/300
Description:
Some providers support authentication by launching into their iOS app directly rather than using Safari or other web views.
OAuth Provider (Twitter, Github, ..):
Facebook and Dropbox
OAuth Version:
OS (Please fill the version) :
Installation method:
Library version:
Xcode version:
I have Facebook somewhat working and Dropbox too. I will provide the details of each in a follow-up comment. My version is very much a hack and I am wondering if you have a nicer/cleaner way to accomplish this - or maybe you don't want to support it because it (likely) is not strictly following the OAuth spec(s).
@mikegray commented on GitHub (Oct 20, 2016):
For Facebook, you need to add
fbauth2to yourLSApplicationQueriesSchemesin Info.plist. You will need to addfb<APP_KEY>to your app url types.Then you can check to see if the Facebook app is installed:
If the app is installed, then you can use an
authorizeUrlof"fbauth2://authorize?response_type=token&client_id=\(facebookAppId)&redirect_uri=fb\(facebookAppId)&scope=public_profile"with OAuth2Swift along with a custom OAuthSwiftURLHandlerType:That will launch Facebook via the
fbauth2URL scheme and it will call back into your app using thefb<APP_KEY>url scheme with the appropriate token:That seems to work pretty well for me.
@mikegray commented on GitHub (Oct 20, 2016):
For Dropbox, you can do something pretty similar. Register
dbapi-2inLSApplicationQueriesSchemes. Add an url type to your app for callback ofdb-<APP_KEY>.Check if Dropbox is installed:
Your authorizeUrl will be something like:
"dbapi-2://1/connect?k=\(dropboxAppId)&s=&state=oauth2:\(nonce)"where nonce is random state string. Dropbox example usesUUID().uuidString.The callback does not match what OAuthSwift/OAuth expectations though - it is almost more closely appears like an OAuth v1 response with
oauth_token_secretbeing the important value:db-<APP_KEY>://1/connect?oauth_token_secret=<MY_SECRET>&state=oauth2%3A<NONCE>&uid=<DROPBOX_USER_ID>&oauth_token=oauth2%3A(Note that the%3Ais just:url encoded.)So you would need to either rewrite the url query before passing it into OAuthSwift.handle(url: url), or define the original settings as being OAuth1Swift? This one doesn't fit as neatly in to the current flows in OAuthSwift.
@mikegray commented on GitHub (Oct 20, 2016):
I am happy to submit a PR if this is generally interesting and you want to take it on for the future. Happy for any advice on how best to integrate these into OAuthSwift - custom handler vs. native app handler vs. subclass OAuthSwift vs. other. I am assuming I could have done it differently/better. Sorry, still pretty new to OAuth in general.
@phimage commented on GitHub (Oct 21, 2016):
ok thanks for the detailled informations
I think you can use OAuthSwiftOpenURLExternally, same as your NativeAppHandler
For dropbox it's a little weird but I see frequently mixing implementation when a provider pass to oauth2.
I think they must fix it, and you must edit the url until that
I don't see anything to integrate in OAuthSwift main project
Maybe only wiki page to explain the subtility, how you achieve that etc...
A page named NativeApplication with the two examples
some link for me
@phimage commented on GitHub (Oct 21, 2016):
https://github.com/OAuthSwift/OAuthSwift/wiki/Authenticate-with-Native-Applications
@mikegray commented on GitHub (Oct 21, 2016):
Sounds good, thanks.