Export (0) Print
Expand All

WL.login

Last modified: March 13, 2015

Signs in the user or expands the user's list of scopes, in a Windows Store app using JavaScript or web app.

Because this function can result in launching the consent page prompt, you should call it only in response to a user action, such as clicking a button. Otherwise, the user's web browser might block the popup.

Typically, this function is used by apps that define their own sign-in controls, or by apps that ask users to grant additional permissions during an activity. For example, to enable a user to post his or her status to a service using Microsoft account, your app may have to prompt the user for permission and call this function with an expanded scope.

If you call this function when the user has already consented to the requested scope and is already signed in, the callback function is invoked immediately with the current session.

This function logs errors to the web browser console.

Parameters

  • properties

    Required. A JSON object formatted with the following properties.

    Name

    Type

    Description

    Default Value

    redirect_uri

    string

    This parameter only applies to web apps.

    Optional. Contains the redirect URI to be used for OAuth authentication. This value overrides the default redirect URI that is provided in the call to WL.init.

    The redirect_uri value specified in WL.init.

    scope

    string or array of string values

    Required. Specifies the scopes to which the user who is signing in consents.

    For a single scope, use this format: scope: "wl.signin". For multiple scopes, use this format: scope: ["wl.signin", "wl.basic"].

    If no scope is provided, the scope value of WL.init is used. If no scope is provided in WL.init or WL.login, WL.login returns an error.

    Note Note

    WL.login can request the "wl.offline_access" scope, but it requires a server-side implementation, and the WL.init function must set its response_type property to "code".

    None.

    state

    string

    Windows Store apps using JavaScript: not applicable.

    Web apps: Optional. If the WL.init function's response_type object is set to "code" and the app uses server-flow authentication, the state object here can be used to track the web app's calling state on the web app server side.

    None.

  • callback

    Optional. Specifies a callback function to execute when sign-in is complete. The callback function takes the status object as a parameter. For a description of the status object, see WL.getLoginStatus. If you do not specify a callback function, your app can still get the sign-in callback info by listening for an auth.sessionChange or auth.statusChange event.

    Note Note

    Although the callback parameter is still supported, we recommend that you use the Promise object instead.

Return value

Returns a Promiseobject. This object's then method provides the onSuccess, onError, and onProgress parameters to enable your code to handle a successful, failed, and in-progress call to the corresponding WL.login method, respectively.

Examples

The following example demonstrates how to sign in a user.

function streamlineAccountReg_onClick() {
    WL.login({
        scope: ["wl.signin", "wl.basic", "wl.birthday", "wl.emails"]
    }).then(
        function (response) {
            WL.api({
                path: "me",
                method: "GET"
            }).then(
                function (response) {
                    document.getElementById("first_name").innerText = response.first_name;
                    document.getElementById("last_name").innerText = response.last_name;
                    document.getElementById("email").innerText = response.emails.preferred;
                    document.getElementById("gender").innerText = response.gender;
                    document.getElementById("birthday").innerText =
                        response.birth_month + " " + response.birth_day + " " + response.birth_year;
                },
                function (responseFailed) {
                    document.getElementById("infoArea").innerText =
                        "Error calling API: " + responseFailed.error.message;
                }
            );
        }, 
        function (responseFailed)
        {
            document.getElementById("infoArea").innerText =
                "Error signing in: " + responseFailed.error_description;
        }
    );
}

Requirements

Library

Wl.js

Show:
© 2015 Microsoft