如何使用Chrome扩展程序获取Laravel护照令牌?

时间:2019-07-21 16:38:32

标签: javascript laravel google-chrome-extension oauth-2.0

我正在使用Chrome扩展访问Laravel护照API。目前,Laravel护照API已设置并正在运行。我试图使用chrome.identity.launchWebAuthFlow来获取护照令牌,但是没有用。 Google提供了一个示例,它与我的用例不同。

我有两个问题:

  1. 根据Laravel document,第一步是request an authorization code,API端点是/oauth/authorizeredirect_uri应该是什么,因为它是chrome扩展名而不是网站?

  2. 用户批准请求后,我使用chrome.identity.launchWebAuthFlow从Passport获取访问令牌。在laravel中,这是一个POST请求,终点是/oauth/token。但是我尝试了chrome.identity.launchWebAuthFlow,这是一个GET请求。

我可以使用PHP而不是Chrome扩展程序使整个过程正常运行。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

根据launchWebAuthFlow文档:

  

当提供程序重定向到与模式https://app-id.chromiumapp.org/ *匹配的URL时,窗口将关闭,最终的重定向URL将传递给回调函数。

作为示例,您可以使用以下代码:

let redirectUrl = chrome.identity.getRedirectURL('redirect');

chrome.identity.launchWebAuthFlow({
    url: `https://my.app.domain.com/oauth/authorize?client_id=xxx&response_type=code&scope=&redirect_uri=${redirectUrl}`
}, (redirectUrl) => {
    console.log(redirectUrl) // Redirect URL with oauth query params added
})