Had to ask this question as I couldn't find the correct way of asking Google.
I am building a browser extension that requires the user to login using his/her credentials.
Lets keep the OAuth2 way aside for a moment there. After logging in, I am storing the JWT token received from the server in the local storage.
Now when the user navigates to another website, the extension does not have access to the stored local storage data due to cross domain access restriction.
I would like to know if there is any way to maintain the session across multiple domain. Can't ask the user to keep on logging in for every other site, he/she navigates to.
Anywhere else we can store the token to make it accessible everywhere?
Edit:
- For the storage via content script, have used
chrome.storage.local. - On page load, the content script sets the value from the
chrome.storage.localintowindow.localStorage, if any. - An iframe is embedded into the web page. Display none by default. Iframe does not have any URL set.
- Then User clicks on the browser Action button, the iframe is displayed.
- User enter the login credentials. These are captured by the script file loaded in the head section of that iframe.
- Now on submit, AJAX call is made and then on its success, stores the JWT token in the storage via
window.localStorage.
Here, I also want to store the same token in the chrome.storage.local so that when the page is refresh or navigated to another domain, the Step 2 from above will execute and set the window.localStorage with the same token as the previous one has. This way, user is logged in already.
Anything wrong with the above? If not, then how to send the token from the iframe to the content or background script?