简体   繁体   English

来自 chrome 扩展的登录用户

[英]login user from chrome extension

I need help in authenticate user login from chrome extension with jwt我需要帮助使用 jwt 从 chrome 扩展验证用户登录

This is my manifest file这是我的清单文件

    {
  "manifest_version": 2,
  "name": "Time tracker",
  "description": "use this extension to send url and time to server",
  "author": "Ashkan Ganj",
  "version": "1.0",
  "browser_action": {
    "default_icon": "/icons/16.png",
    "default_title": "Time Tracker",
    "default_popup":"popup.html"
  },
  "permissions": [
    "tabs",
    "activeTab",
    "http://127.0.0.1:8000/*",
    "https://jsonplaceholder.typicode.com/posts",
    "storage",
    "http://*/", 
    "https://*/"

  ],
  "content_scripts": 
  [
      {
          "matches": ["http://127.0.0.1:8000/*","https://jsonplaceholder.typicode.com/posts"],  
          "js": ["packages/jquery-3.5.0.min.js","popup.js"]
      }
  ],

  "background": {
    "scripts": [
      "background.js","packages/jquery-3.5.0.min.js"
    ],
    "persistent": false
  }
}

and my popup js to send login info, my problem is: how to send request and get access and refresh token and store them in session storage in order to login user和我的弹出 js 发送登录信息,我的问题是:如何发送请求并获取访问和刷新令牌并将它们存储在 session 存储中以便登录用户

$("#submitbtn").click(function (sendReq) {
  var email = $("#email").val();
  var password = $("#password").val();
  sessionStorage.setItem("userToken", "");
});
function sendReq() {
  let sendReq = (ev) => {
    let url = "/api/token";
    let h = new Headers();
    let req = new Request(url, {
      method: "POST",
      mode: "cors",
    });
    fetch(req)
      .then((resp) => resp.json())
      .then((data) => {
        console.log(data[0]);
      })
      .catch((err) => {
        console.error(err.message);
      });
  };
}

my path to get token and refresh token api/token and api/token/refresh my rest framework get token pic我获取令牌和刷新令牌的路径 api/token 和 api/token/refresh我的 rest 框架获取令牌图片

Thanks for your helps.感谢您的帮助。

Fisrt thing first, Use background.js for API calls and send the 200 response to popup as message passing between popup and background then set the browserAction to any other html you want to show after successful login.首先,将 background.js 用于 API 调用并将 200 响应作为弹出窗口和后台之间的消息传递发送到弹出窗口,然后将 browserAction 设置为您想要在成功登录后显示的任何其他 html。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM