我正在使用Chrome扩展访问Laravel护照API。目前,Laravel护照API已设置并正在运行。我试图使用chrome.identity.launchWebAuthFlow
来获取护照令牌,但是没有用。 Google提供了一个示例,它与我的用例不同。
我有两个问题:
根据Laravel document,第一步是request an authorization code
,API端点是/oauth/authorize
。 redirect_uri
应该是什么,因为它是chrome扩展名而不是网站?
用户批准请求后,我使用chrome.identity.launchWebAuthFlow
从Passport获取访问令牌。在laravel中,这是一个POST请求,终点是/oauth/token
。但是我尝试了chrome.identity.launchWebAuthFlow
,这是一个GET请求。
我可以使用PHP而不是Chrome扩展程序使整个过程正常运行。有什么建议吗?
答案 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
})