Send authentication token to Safari from iOS App to Safari

丶灬走出姿态 提交于 2019-12-12 09:01:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!