[英]Google oauth authentication login
我正在制作一个 gmail 扩展并尝试通过 Google oauth 登录我的网站,我在我的扩展文件夹中添加了以下代码并使用 gmail.js 插件编写扩展代码。
gmail.tools.add_compose_button(compose_ref, '<script src = "https://plus.google.com/js/client:platform.js" async defer></script> <div id="gConnect" class="button"><button class="g-signin" data-scope="email"data-clientid="787518087911-shac261d8d66ig523j8foql7f4v3k03m.apps.googleusercontent.com" class="callback" data-theme="dark"data-cookiepolicy="single_host_origin"></button><div id="response" class="hide"><textarea id="responseContainer" style="width:100%; height:150px"></textarea></div></div>',
function() {
$(document).on("click",".callback",function(){
debugger;
var primaryEmail;
for (var i=0; i < resp.emails.length; i++) {
if (resp.emails[i].type === 'account') primaryEmail = resp.emails[i].value;
}
document.getElementById('responseContainer').value = 'Primary email: ' +
primaryEmail + '\n\nFull Response:\n' + JSON.stringify(resp);
gapi.client.load('plus', 'v1', gapi.client.plus.people.get({userId: 'me'}).execute(document.getElementById('responseContainer').value));
我需要访问登录的用户 ID,我还在清单文件中添加了这一行:- "content_security_policy":"script-src 'self' https://apis.google.com; object-src 'self'",
但我收到以下错误:
拒绝执行 JavaScript URL,因为它违反了以下内容安全策略指令:“script-src 'nonce-UZ+ZHhZXVg4JFwAmZj9CQinub9Y' 'strict-dynamic' 'unsafe-eval' 'unsafe-inline' https: 'report-sample'”。 请注意,如果源列表中存在哈希值或现时值,则忽略 'unsafe-inline'。
任何帮助将不胜感激。
您是否在 google API 控制台中对 URL 进行了授权? 您必须将 URL 添加到 oAuth 白名单。
您可以在此处进行设置: https : //console.developers.google.com
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.