您好我正在尝试使用Microsoft OAuth,以便能够使用Chrome扩展程序内的Outlook凭据登录。
我正在使用javascript库(https://msdn.microsoft.com/en-us/library/hh550844.aspx),但我无法做到。我正在做以下事情。
WL.init({
client_id: "foo_bar",
scope: "wl.signin",
redirect_uri:"http://www.contoso.com/redirect",
response_type: "token" });
然后
WL.login()
正在发生的事情是我被重定向到http://www.contoso.com/redirect 但当我关闭弹出窗口时,我收到以下消息
[WL] WL.login:未经同意,弹出窗口已关闭。
我认为问题是redirect_uri但是如何使用chrome扩展程序?
答案 0 :(得分:0)
我终于做到了。请遵循本指南
你在这里有代码
https://github.com/jameslau-MSFT/MSAuthFromChromeExtSample
高级步骤
以下是您需要在高级别做的事情:
清单应该是这样的
{
"name": "MSAuthFromChromeExtSample",
"short_name": "MSAChromeExt",
"version": "1.0.0",
"description": "Chrome extension that demonstrates how to authenticate against Microsoft Account.",
/*"background":{
"page": "background.html"
},*/
"browser_action": {
/* "default_icon": {
"19": "./assets/icons/icon-19.png",
"38": "./assets/icons/icon-38.png"
},*/
"default_title": "MSA Auth Sample",
"default_popup": "./html/popup.html"
},
"content_scripts": [
{
"matches": ["*://*/*"],
"js": ["lib/jquery.min.js", "js/script.js"],
"run_at" : "document_end"
}
],
"permissions": ["history","tabs","storage", "webRequest", "notifications", "<all_urls>"],
"manifest_version": 2,
"update_url": "http://clients2.google.com/service/update2/crx",
"content_security_policy": "script-src 'self' https://js.live.net; object-src 'self'"
}
要指出的一些事项:
登录代码
$('a#signin').click(function() {
$('div#signin_status').text('');
WL.init({
client_id: "000000004410CD1A", // replace with your own Client ID!!
redirect_uri: "https://login.live.com/oauth20_desktop.srf",
response_type: "token"
});
WL.login({
scope: ["wl.signin", "office.onenote_create"]
});
return false;
});
内容脚本
$(window).load(function() {
if (window.location.origin == "https://login.live.com") {
var hash = window.location.hash;
// get access token
var start = hash.indexOf("#access_token=");
if ( start >= 0 ) {
start = start + "#access_token=".length;
var end = hash.indexOf("&token_type");
var access_token = hash.substring(start, end);
// Store it
chrome.storage.local.set({"access_token":access_token});
// Close the window
window.close();
}
}
});