我使用chrome.identity.launchWebAuthFlow
让用户可以使用FB OAuth 2.0登录,这在unpacked下完美运行。
但是,当我打包镀铬扩展。
身份验证完全失败了。
我只想确认是否有人成功将Facebook OAuth与Chrome扩展程序集成。也许FB白名单政策完全不能完成这项工作。
答案 0 :(得分:0)
您可以将 manifest.json
中的重定向URI列入白名单吗?<强>实施例强>
"content_security_policy": "script-src 'self' https://*.facebook.com;
以下Facebook OAuth登录代码正常运行:
<强>的manifest.json 强>
{
"name": "Facebook Sample",
"description": "Facebook Sample",
"version": "1",
"manifest_version": 2,
"minimum_chrome_version": "29",
"browser_action": {
"default_popup": "index.html"
},
"permissions": ["identity", "https://*.facebook.com/*"]
}
index.html和index.js
onload = function() {
var login = document.getElementById("login");
login.onclick = function() {
var redirectUrl = chrome.identity.getRedirectURL();
var clientId = "1ac94815c30440efa6f7de3c0d529515";
var authUrl = "https://facebook.com/oauth/authorize/?" +
"client_id=" + clientId + "&" +
"response_type=token&" +
"redirect_uri=" + encodeURIComponent(redirectUrl);
chrome.identity.launchWebAuthFlow({url: authUrl, interactive: true},
function(responseUrl) {
console.log(responseUrl);
var accessToken = responseUrl.substring(responseUrl.indexOf("=") + 1);
console.log(accessToken);
});
};
};
var facebookAPI = function(accessToken) {
this.request = function(method, arguments, callback) {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
callback(JSON.parse(xhr.response));
};
xhr.open("GET", "https://api.facebook.com/v1/" + method + "?access_token=" + accessToken);
xhr.send();
};
}
&#13;
<html>
<head>
<title>Facebook Login</title>
<script src="index.js"></script>
</head>
<body>
<button id="login">Facebook Log in</button>
</body>
</html>
&#13;