Reputation: 2924
I am trying to replace the login screen of a website with a custom, native one.
The way the website is set up, the login UI is on the front page (http://www.example.com/), that then AJAX the credentials to the API (http://API.example.com/). Because of this, setting the Auth Header on the front page does not work, and it needs to be set the first time hitting the API.
My idea was to send a login request to the API through NSURLRequest
, which workd great by itself. However, the token is not retained or shared with WKWebview, therefore the front page does not recognise the user as logged in.
Is there a way to share that Auth Token between the two requests, or to add an Auth Token to a page requested through AJAX? Thank you.
Upvotes: 1
Views: 1020
Reputation: 1694
Check out NSURLProtocol
, it defines how URLs are loaded in an application. You could inject your credentials/sessionId in each request in your application after the login was successful.
Here is a great tutorial : http://nshipster.com/nsurlprotocol/ and one with webviews : http://www.raywenderlich.com/59982/nsurlprotocol-tutorial
Upvotes: 1