Get and store auth_token in chrome extension

為{幸葍}努か 提交于 2019-12-13 07:52:00

问题


I am implementing a chrome extension. Where an user log in(email and password) and get auth token from 3rd party. I want to store this auth token so when sending another request to same party I can use this token. What is good approach to do this. Should I store it ? If yes how? Else what should I do?


回答1:


you can save it in Storage

Step 1 :- You need to add the permission in menifist, json

"permissions": [ "storage" ],

Steps 2 :- Set token to the storage

chrome.storage.local.set({ "auth_Tokan": <YOUR_TOKAN_HERE> }, function(){
    //  Data's been saved boys and girls, go on home
});

Steps 3 :- Get the token from the storage

var Auth_Tokan='';
chrome.storage.local.get(["auth_Tokan"], function(items){
    debugger;
    //NOTE:-check syntax here, i am not sure for access  'Auth_Tokan'
    auth_tokan= items.Auth_Tokan
});


来源:https://stackoverflow.com/questions/48077497/get-and-store-auth-token-in-chrome-extension

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