我正尝试创建一个Chrome扩展程序,用户可以使用其Google帐户登录。我已将其基于此示例代码:https://developers.google.com/+/quickstart/javascript,它得到的最多为gapi.auth2.init
,但随后的Error: redirect_uri_mismatch
发生了400个错误。客户端ID已被正确注册。使用G +登录的Chrome扩展程序 - redirect_uri_mismatch
由于redirect_uri错误,API调用失败,但是我为扩展设置了什么URI?该API调用时像这样:
gapi.auth2.init({
fetch_basic_profile: false,
client_id: '1234_valid_id_1234',
cookie_policy: 'none',
redirect_uri: 'xxx',
scope:'https://www.googleapis.com/auth/plus.login'
}).then(
“XXX”作为URI仅仅是一个例子,我试过的众多选择在这里,无济于事。
该扩展将加载一个对话,就好像它将开始认证过程,但随后出现400错误。我不明白什么URI扩展应该提供作为回调在这里,当然这不适用?
客户端ID等是好的 - 如果我只是在一个标准的本地主机网站上运行示例JS代码它一切正常,它只是当试图在它打破的扩展中使用它,因为缺乏回调URI 。
您必须放置'postmessage'而不是实际的URI。请参阅:http://stackoverflow.com/questions/11485271/google-oauth-2-authorization-error-redirect-uri-mismatch和http://stackoverflow.com/questions/17954086/google-oauth2-authorizing-oauth -token-error-redirect-uri-mismatch/17976227#17976227 – gui47
这没有什么区别。无论我改变redirect_uri,我总会看到redirect_uri设置为“storagerelay:// chrome-extension/appidinhere?id = auth963268”时返回的错误。我似乎无法覆盖这一点,我不知道什么sotragerelay或它来自哪里。 – artparks
你有没有找到相同的解决方案? – pd176