问题
I have some URLs in my app which takes the user to Safari browser through openURL
API.
My aim is to sent the auth token to Safari from the app, so that user will be logged in by using this token. Our server requires this ticket to be sent as part of header information. Is there any possibility to sent custom headers along with NSURL
?
I have checked the below link which talks about query components but the server doesn't handle it, they prefer a different solution. Android is having some possibility to sent additional headers when opening a URL in external browser, so now every eye is on iOS :-).
Open NSURLRequest In Safari
The auth token is saved in a shared keychain, is there a way in which Safari can access it?
What is the recommended solution?
Do I need to use Shared Web Credentials? Quite some work required in this case I believe. I have not used it.
回答1:
I think you need to play at the level of the URL. Say you send from the server a one-time token to the app and use it in the URL you are sending to Safari as a parameter.
When the server receives the token it will automatically know who the user is, continuing it's session, now from Safari.
The first link you provided explain this idea and I think it can fit you, but you need to update also the backend to perform such task.
Something like
UIApplication.sharedApplication().openURL(NSURL(string:"http://www.myWebsite/user?token=\(userToken)")!)
回答2:
Finally decided to go with webview as our auth ticket is too long for a url, thanks for the help
来源:https://stackoverflow.com/questions/32995648/send-authentication-token-to-safari-from-ios-app-to-safari