简体   繁体   中英

What's the role of callbackURLScheme in ASWebAuthenticationSession/SFAuthenticationSession?

I am quite surprise I can't fine any more or less clear explanation of how exactly the logic with callbackURLScheme (incl. completionHandler) works .

Yes, in general, it's kind of clear that it has something with the url schema, which can be specified in plist file, and the way Deep Linking works.

However,

  • how exactly it is bound to the ASWebAuthenticationSession/SFAuthenticationSession flow? I mean, does it looks for similar pattern in the browser url and if it becomes equals, it intercepts the response, closes the browser window and returns access to the app?

  • what if don't have the url schema defined, but I am just using Associated Domains? Should I specify the "return" url passed to the server, or there should be the schema anyways?

  • what if I pass null for it? There are some notes over the Internet, that in some magical way it get's bound to plist file, but, again, no particular documentation about that.

Really appreciate the answers!

The ASWebAuthenticationSession is really shrouded in mystery a bit. Swift header can shed some light. (Jump to definition: Command + right click on ASWebAuthenticationSession class in Xcode)

On completion, the service will send a callback URL with an authentication token, and this URL will be passed to the app by ASWebAuthenticationSessionCompletionHandler. The callback URL usually has a custom URL scheme. For the app to receive the callback URL, it needs to either register the custom URL scheme in its Info.plist, or set the scheme to callbackURLScheme argument in the initializer.

Actually my test shown that on ios 14 it works as described. You need either register custom URL scheme and provide nil for corresponding argument or just put the argument. Or both. Completion on successful login is called as expected. It is not mentioned in the documentation with such details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM