Javascript chrome扩展上的实时连接

Javascript chrome扩展上的实时连接,javascript,google-chrome,google-chrome-extension,oauth-2.0,liveconnect,Javascript,Google Chrome,Google Chrome Extension,Oauth 2.0,Liveconnect,您好,我正在尝试使用Microsoft OAuth,以便能够在chrome扩展中使用Outlook凭据登录 我正在使用javascript库,但我无法做到这一点。我正在做以下工作 WL.init({ client_id: "foo_bar", scope: "wl.signin", redirect_uri:"http://www.contoso.com/redirect", response_type: "token" }); 然后 WL.login() 发

您好,我正在尝试使用Microsoft OAuth,以便能够在chrome扩展中使用Outlook凭据登录

我正在使用javascript库,但我无法做到这一点。我正在做以下工作

WL.init({
    client_id: "foo_bar",
    scope: "wl.signin",
    redirect_uri:"http://www.contoso.com/redirect",
    response_type: "token" });
然后

WL.login()
发生的事情是我被重定向到 但是当我关闭弹出窗口时,我得到以下消息

[WL]WL.login:未经同意,弹出窗口关闭


我认为问题在于重定向uri,但如何使用chrome扩展实现这一点?

我终于做到了。按照这个指南去做就行了

这里有代码

高级步骤

以下是您需要在高级别上执行的操作:

创建客户端ID并确保API设置正确。 正确设置Chrome扩展以使用至少1个内容脚本。我们将需要它在下面的4。 在Chrome扩展中创建要登录的UI,确保将重定向URL正确设置为“”,并将响应类型设置为“令牌”。 在Chrome扩展的内容脚本中,注意Microsoft帐户登录流中的弹出窗口。在正确的时间点,我们将捕获auth_令牌,存储它,然后关闭弹出窗口。 清单应该是这样的

{
  "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'"
}
内容脚本


这些文件有一个oauth样本。我知道但不起作用。不起作用不会让你在s.o.上走得更远。我不知道我能告诉你更多什么。正如我在问题中所说,我收到消息[WL]WL.login:弹出窗口在未获得同意的情况下关闭。我怀疑是来自redirect_uri,但我不确定。但是如果您查看oauth扩展示例库not identity,您将看到它读回令牌的技巧,它们可能在您的特定情况下不起作用。在做我需要的google和trello的OAuth时,它对我很有效,所以在堆栈溢出上不欢迎只提供链接的答案。在此处包括解决方案的相关部分。
$('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();
        }
    }
});