在Chrome扩展程序中获取并存储auth_token

问题描述:

我正在实现chrome扩展程序.用户登录(电子邮件和密码)并从第三方获得身份验证令牌的位置.我想存储此身份验证令牌,因此当向同一方发送另一个请求时,我可以使用此令牌.有什么好的方法可以做到这一点.我应该储存吗?如果是,怎么办?否则我该怎么办?

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?

您可以将其保存在存储空间中

you can save it in Storage

步骤1:-您需要在menifistjson

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

权限":[ 贮存" ]

"permissions": [ "storage" ],

第2步:-将令牌设置为存储空间

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
});

第3步:-从存储中获取令牌

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
});