Get and store auth_token in chrome extension

2019-09-20 17:31发布

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条回答
孤傲高冷的网名
2楼-- · 2019-09-20 18:18

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
});
查看更多
登录 后发表回答