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.

anoop4real
  • 7,598
  • 4
  • 53
  • 56

2 Answers2

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)")!)
r4id4
  • 5,877
  • 8
  • 46
  • 76
  • My doubt is on how to sent the token as parameter to Safari? Querycomponent is the only option? – anoop4real Oct 07 '15 at 21:40
  • 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. – r4id4 Oct 07 '15 at 22:26
  • Finally decided to go with webview as our auth ticket is too long for a url, thanks for the help – anoop4real Oct 23 '15 at 09:24
1

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

anoop4real
  • 7,598
  • 4
  • 53
  • 56