WL.init

Initializes the Live SDK JavaScript library.

A Windows Store app using JavaScript or web app must call this function on every page before making other function calls in the library. The app should call this function before making function calls that subscribe to events. If the JavaScript library has already been initialized on the page, calling this function succeeds silently; the client_id and redirect_uri parameters are not validated.

Parameters

  • properties

    Required. A JSON object that must be formatted with the following properties.

    Property

    Type

    Description

    Default Value

    client_id

    string

    Web apps: Required. Specifies your app's OAuth client ID for web apps.

    Windows Store apps using JavaScript: not needed.

    None.

    redirect_uri

    string

    Required. Contains the default redirect URI to be used for OAuth authentication. For web apps, the OAuth server redirects to this URI during the OAuth flow.

    For Windows Store apps using JavaScript, specifying this value will enable the library to return the authentication token.

    Web apps: the URL of the current page.

    Windows Store apps using JavaScript: none.

    scope

    string

    Optional. The scope values used to determine which portions of user data the app has access to, if the user consents.

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

    None.

    logging

    boolean

    Optional. If set to "true", the library logs error info to the web browser console and notifies your app by means of the wl.log event.

    "true"

    status

    boolean

    Web apps: optional.

    Windows Store apps using JavaScript: not applicable.

    If set to "true", the library attempts to retrieve the user's sign-in status from Live Connect.

    "true"

    response_type

    string

    Web apps: optional.

    Windows Store apps using JavaScript: not applicable.

    Specifies the OAuth response type value. If set to "token", the client receives the access token directly. If set to "code", the client receives an authorization code, and the app server that serves the redirect_uri page should retrieve the access_token from the OAuth server by using the authorization code and client secret.

    You can only set response_type to "code" for web apps.

    "token"

    secure_cookie

    string

    Web apps: optional.

    Windows Store apps using JavaScript: not applicable.

    Optional. If set to "true", the library specifies a secure attribute when writing a cookie on an HTTPS page.

    "false"

Return value

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

When the onSuccess callback is invoked, a login status object is passed in as parameter that indicates the current user's login status.

Examples

Web sites can call WL.init as shown here.

WL.init({
    client_id: APP_CLIENT_ID,
    redirect_uri: REDIRECT_URL,
    scope: "wl.signin", 
    response_type: "token"
});

Windows Store apps using JavaScript can call WL.init like this.

WL.init({scope: "wl.signin"});

Requirements

Library

Wl.js