Send authentication token to Safari from iOS App to Safari
Asked Answered
I

2

2

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.

Incorporeal answered 7/10, 2015 at 14:57 Comment(0)
I
1

Finally decided to go with webview as our auth ticket is too long for a url, thanks for the help

Incorporeal answered 23/10, 2015 at 9:25 Comment(0)
P
2

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)")!)
Piecrust answered 7/10, 2015 at 21:20 Comment(3)
My doubt is on how to sent the token as parameter to Safari? Querycomponent is the only option?Incorporeal
I think it is if you with to launch Safari. I could not find a counterexample that allows to work on headers or so. Anyway I edited adding a snippet of Swift code to do the job.Piecrust
Finally decided to go with webview as our auth ticket is too long for a url, thanks for the helpIncorporeal
I
1

Finally decided to go with webview as our auth ticket is too long for a url, thanks for the help

Incorporeal answered 23/10, 2015 at 9:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.