windows live login get email address

606 views Asked by At

I am trying to implement windows live login using their javascript API. I am referring to this documentation as an example and using the following code:

WL.Event.subscribe("auth.login", onLogin);
        WL.init({
            client_id: 'my client id',
            redirect_uri: 'redirect uri',
            scope: ["wl.signin", "wl.basic"],
            response_type: "token"
        });
        WL.ui({
            name: "signin",
            element: "signin"
        });
        function onLogin(session) {
            if (!session.error) {
                WL.api({
                    path: "me",
                    method: "GET"
                }).then(
                    function (response) {
                        console.log(response);
                        document.getElementById("info").innerText =
                            "Hello, " + response.first_name + " " + response.last_name + "!";
                    },
                    function (responseFailed) {
                        document.getElementById("info").innerText =
                            "Error calling API: " + responseFailed.error.message;
                    }
                );
            }
            else {
                document.getElementById("info").innerText =
                    "Error signing in: " + session.error_description;
            }
        }

The above code is returning id, name and other fields but I also want to get user's email and profile picture url fields like how it is returned in the google+ API by mentioning email in the scope. I have gone through WL.init documentation and there is no mention of email and profile picture url scope values. Any way to get these two fields?

1

There are 1 answers

0
Michael Biermann On

Regarding scopes have a look at https://msdn.microsoft.com/en-us/library/hh243646.aspx#core

You need "wl.emails" for the emails of the user 'me'. For the user's picture you do not need special scope

var scope = {scope:["wl.signin", "wl.basic", "wl.emails"]};
WL.login(scope, windowsLiveLoginCallback);

...

WL.api({
    path: "me",
    method: "GET"
}).then(
    function (response){
        var email = "";
        if(response.emails.preferred){
           email = response.emails.preferred;
        }
        else if(response.emails.account){
           email = response.emails.account;
        }
        WL.api({
           path: "me/picture",
           method: "GET"
        }).then(
            function(pictureResponse){
                // pictureResponse.location
            },
            function (responseFailed){
                console.log('WL.api(me) error: ', responseFailed);
            }
        );
    },
    function (responseFailed){
        console.log('WL.api(me) error: ', responseFailed);
    }
);