简体   繁体   English

Chrome 扩展程序从 header 获取授权令牌

[英]Chrome extension get authorization token from header

I'm working on an extension that will make request to Robinhood API and get all transaction history to generate a better report.我正在开发一个扩展程序,它将向 Robinhood API 发出请求并获取所有交易历史记录以生成更好的报告。

Initial thought, it will be easier to just grab auth token from chrome extension(background.js) and use that to make request to Robinhood API but seems like it's more complicated than I expected.最初的想法是,从 chrome 扩展程序 (background.js) 中获取 auth 令牌并使用它向 Robinhood API 发出请求会更容易,但似乎比我预期的要复杂。

I can still see the authorization token on the Chrome browser console but can't find the way to grab that from my Chrome extension(pic below)我仍然可以在 Chrome 浏览器控制台上看到授权令牌,但无法找到从我的 Chrome 扩展中获取它的方法(下图)

在此处输入图像描述

Thought webRequest API is the answer but found it won't provide Authorization info( https://developer.chrome.com/docs/extensions/reference/webRequest/ )认为 webRequest API 是答案,但发现它不会提供授权信息( https://developer.chrome.com/docs/extensions/reference/webRequest/

chrome.webRequest.onBeforeSendHeaders.addListener((details) => {
    console.log(details);
  }, 
  { urls: ["<all_urls>"] },
  ["requestHeaders", "extraHeaders"]
);

I know there's Chrome extensions making http requests to Robinhood API with local auth token.我知道有 Chrome 扩展程序使用本地身份验证令牌向 Robinhood API 发出 http 请求。 What's the best way to grab that local auth token?获取本地身份验证令牌的最佳方式是什么?

Thank you all!谢谢你们!

Thank you to @wOxxOm for the answer!感谢@wOxxOm 的回答!

I was missing host_permissions in manifest.json.我在 manifest.json 中缺少host_permissions The Authorization token info shows up after adding that.添加后会显示授权令牌信息。

在此处输入图像描述

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

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