MobileServiceClient.login function

Logs a user into a mobile service by using the specified identity provider.

mobileServiceClient.login(provider, token);

Parameters

  • provider
    Type: string

    The name of the identity provider, which instructs Mobile Services which provider to use for authentication. The following values are supported:

    Provider value Description

    microsoftaccount

    Microsoft Account login.

    facebook

    Facebook login

    twitter

    Twitter login

    google

    Google login

  • token
    Type: string

    Optional JSON representation of an authentication token, which can be supplied when the client has already obtained a token from the identity provider.

  • useSingleSignOn
    Type: boolean

    Indicates whether to use single sign-on when logging in. Only supported in a Windows Store app.

Return Value

Type: Promise object that returns a user object when it completes.

Call the done method on the returned Promise object to access the returned user and handle any errors.

Example

The following code authenticates the user by using a Facebook login, and then accesses the returned user ID value.

mobileService.login("facebook").done(function (results) {
    var userId = results.userId;
    // Do something with the user ID.
}

Remarks

When you set the useSingleSignOn value to true, Mobile Services will attempt to login using credentials cached on the client. To be able to use this functionality, you must have also registered your Windows Store app package information with Mobile Services. For information on how to register your app package, see the tutorial Get started with push notifications in Mobile Services.

.NET Framework Equivalent

LoginAsync

Requirements

Namespace

WindowsAzure.MobileServices

Library

MobileServices.js

See Also

Reference

MobileServiceClient object

Other Resources

Get started with authentication
How to use an HTML/JavaScript client for Azure Mobile Services