1

我的网络应用程序中有一个“使用 Google 登录”按钮,该按钮打开同意窗口,在用户登录后获取代码并将其发送到我的服务器,以进行服务器端验证。这是我使用的 Javascript 代码:

gapi.load('auth2', function() {
    auth2 = gapi.auth2.init({
        client_id: CLIENT_ID,
        scope: googleScopes
    });
});
$('#signInButtonGoogle').click(function() {
    auth2.grantOfflineAccess({'redirect_uri': 'postmessage', 'approval_prompt' : 'force'}).then(onGoogleSignIn);
});

我正在尝试实现一个“使用 Outlook.com 登录”按钮,它应该做的完全一样,但它似乎缺少谷歌的一些功能,尤其是 'redirect_uri': 'postmessage' 重定向 URI 和 'approval_prompt' : '力量'。

这是我当前的 Microsoft Live Connect Javascript 代码:

WL.Event.subscribe("auth.login", onMsnSignIn); <== never got to a point where this actually worked
WL.init({
    client_id: CLIENT_ID,
    redirect_uri: REDIRCT_URI, <== no 'postmessage' option :-(
    scope: "wl.signin",
    response_type: "code"
});
// this is instead of 'approval_prompt' : 'force', but I'm not sure it really works
WL.getLoginStatus(function(response) {
    if (response.status == 'connected') {
        WL.logout();
    }
});
$('#signInButtonLive').click(function () {
    WL.login({
        scope: msnScopes // additional scopes required
    }).then(
        // this works only when I have a session in another Microsoft site, like MSDN
        // but I want to force the user to sign in with the right Live ID
        function (session) {
            console.log(session);
            WL.api({
                path: "me",
                method: "GET"
            }).then(
                function (response) {
                    console.log(response)
                })
        },
        function (sessionError) {
            console.log('error');
        }
    );
});

那么有没有办法拥有与谷歌登录类似的功能?

MS Live 中是否有“postmessage”和“force”的替代方法?

是否有可能在处理程序中实现相同的目标,由redirect_uri 指向?我没有找到这个处理程序的任何示例,除了接收和传递代码之外,它应该关闭同意窗口。

4

0 回答 0