[GH-ISSUE #338] authorizeURLHandler: How do I know when OAuthSwift has sent the user to Safari? #209

Closed
opened 2026-03-03 16:46:42 +03:00 by kerem · 5 comments
Owner

Originally created by @dannymout on GitHub (Feb 16, 2017).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/338

Description:

In my app, I want to get a token, so I'll send my user to the OAuth provider, I'm doing this by redirecting them to Safari:

OAuthSwift.authorizeURLHandler = OAuthSwiftOpenURLExternally.sharedInstance

Everything works perfectly, but one question: How do I know when my app has sent the user to Safari?

OAuth Provider (Twitter, Github, ..):

Not important.

OAuth Version:

  • Version 1
  • Version 2

OS (Please fill the version) :

  • iOS :
  • OSX :
  • TVOS :
  • WatchOS :

Installation method:

  • Carthage
  • CocoaPods
  • Manually

Library version:

  • head
  • v1.0.0
  • v0.6
  • other: (Please fill in the version you are using.)

Xcode version:

  • 8.0 (Swift 3.0)

  • 8.0 (Swift 2.3)

  • 7.3.1

  • other: (Please fill in the version you are using.)

  • objective c

Originally created by @dannymout on GitHub (Feb 16, 2017). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/338 ### Description: In my app, I want to get a token, so I'll send my user to the OAuth provider, I'm doing this by redirecting them to Safari: `OAuthSwift.authorizeURLHandler = OAuthSwiftOpenURLExternally.sharedInstance` Everything works perfectly, but one question: How do I know when my app has sent the user to Safari? ### OAuth Provider (Twitter, Github, ..): Not important. ### OAuth Version: - [ ] Version 1 - [X] Version 2 ### OS (Please fill the version) : - [x] iOS : - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [ ] Carthage - [X] CocoaPods - [ ] Manually ### Library version: - [X] head - [ ] v1.0.0 - [ ] v0.6 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [X] 8.0 (Swift 3.0) - [ ] 8.0 (Swift 2.3) - [ ] 7.3.1 - [ ] other: (Please fill in the version you are using.) - [ ] objective c
kerem 2026-03-03 16:46:42 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@phimage commented on GitHub (Feb 17, 2017):

the oauth flow with OAuthSwiftOpenURLExternally :

  • safari is launched
  • safari open the login page for the specific provider
    • safari have its own cookies, so user could be already logged
  • after success full login, callback url is call (and must open your app using url scheme with token as query or fragment parameters)

there is no user information sent from the app to safari

<!-- gh-comment-id:280676693 --> @phimage commented on GitHub (Feb 17, 2017): the oauth flow with `OAuthSwiftOpenURLExternally` : - safari is launched - safari open the login page for the specific provider - safari have its own cookies, so user could be already logged - after success full login, callback url is call (and must open your app using url scheme with token as query or fragment parameters) there is no user information sent from the app to safari
Author
Owner

@dannymout commented on GitHub (Feb 17, 2017):

@phimage Correct, but when using OAuthSwiftOpenURLExternally, the app will automatically send the user to Safari, I don't need any user data. I just want to know when OAuthSwift has redirected to Safari. Is there a way to do that?

<!-- gh-comment-id:280685991 --> @dannymout commented on GitHub (Feb 17, 2017): @phimage Correct, but when using `OAuthSwiftOpenURLExternally`, the app will automatically send the user to Safari, I don't need any user data. I just want to know when OAuthSwift has redirected to Safari. Is there a way to do that?
Author
Owner

@phimage commented on GitHub (Feb 17, 2017):

there is no "user" send to safari
just url open with on iOS : UIApplication.shared.openURL(url)

If you use OAuth version 2, just after calling authorize safari is open immediately
So you know when it's done, because you call authorize

for oauth version 1 is more complicated, there is before a request to the server

Then if you want a clean way to do this, implement your own OAuthSwiftURLHandlerType and use it

open class MonitoredHandler: OAuthSwiftURLHandlerType {

    public static var sharedInstance : MonitoredHandler = MonitoredHandler()
        
    @objc open func handle(_ url: URL) {
        // TODO : here send event : safari will open
         OAuthSwiftOpenURLExternally.handle(url)
       // TODO : here send event : safari did open
    }
}

just for information, OAuthSwiftOpenURLExternally is not recommend, apple do not allow it I think
so for ios9 there is SafariURLHandler with a delegate to know where safari is initialized

<!-- gh-comment-id:280696953 --> @phimage commented on GitHub (Feb 17, 2017): there is no "user" send to safari just url open with on iOS : UIApplication.shared.openURL(url) If you use OAuth version 2, just after calling `authorize` safari is open immediately So you know when it's done, because you call `authorize` for oauth version 1 is more complicated, there is before a request to the server Then if you want a clean way to do this, implement your own `OAuthSwiftURLHandlerType` and use it ```swift open class MonitoredHandler: OAuthSwiftURLHandlerType { public static var sharedInstance : MonitoredHandler = MonitoredHandler() @objc open func handle(_ url: URL) { // TODO : here send event : safari will open OAuthSwiftOpenURLExternally.handle(url) // TODO : here send event : safari did open } } ``` just for information, OAuthSwiftOpenURLExternally is not recommend, apple do not allow it I think so for ios9 there is SafariURLHandler with a delegate to know where safari is initialized
Author
Owner

@dannymout commented on GitHub (Feb 19, 2017):

@phimage OK, so there is a way to open URLs in Safari, that would allow me to get approved by the App Store:

UIApplication.shared.open(NSURL(string:"http://www.reddit.com/") as! URL, options: [:], completionHandler: nil)

How would I set the URL handler to work with that?

<!-- gh-comment-id:280940216 --> @dannymout commented on GitHub (Feb 19, 2017): @phimage OK, so there is a way to open URLs in Safari, that would allow me to get approved by the App Store: ````swift UIApplication.shared.open(NSURL(string:"http://www.reddit.com/") as! URL, options: [:], completionHandler: nil) ```` How would I set the URL handler to work with that?
Author
Owner

@phimage commented on GitHub (Feb 19, 2017):

not in Safari but SFSafariViewController using OAuthSwift SafariURLHandler

and for your question, I don't really understand why you want to open in safari a reddit url... nothing in relation with OAuth

UIApplication.shared.open(url) is equivalent to OAuthSwiftOpenURLExternally.handle(url)

<!-- gh-comment-id:280940858 --> @phimage commented on GitHub (Feb 19, 2017): not in Safari but `SFSafariViewController` using OAuthSwift `SafariURLHandler` and for your question, I don't really understand why you want to open in safari a reddit url... nothing in relation with OAuth `UIApplication.shared.open(url)` is equivalent to `OAuthSwiftOpenURLExternally.handle(url)`
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#209
No description provided.