Authentication Overview
The process of enabling authentication for the user and getting authorization to access XBOX services data consists of three steps. The first step is a one-time provisioning step: Website registration- The website or web app gets an identity provisioned for use with a Microsoft account.
- This registration happens in the publisher’s Microsoft Entra ID.
- The user accesses the website or starts the app.
- The user is redirected to log into their Microsoft account via the OAuth2.0 endpoint.
- The user enters their credentials successfully and consents for the website or app to access XBOX services information on his or her behalf.
- The website or app receives an authorization code.
- The website or app requests an access token, leveraging the authorization code and requesting the correct scope.
- The website or app received an access token (and a refresh token if requested).
- Using the access token, the website or app makes a request for an XBOX services User Token (U Token).
- The User token is then used to obtain X tokens (access tokens) from the XBOX Security Token Service (XSTS) to access XBOX services or title services.
Website Registration
To be able to authenticate a user to a website using a Microsoft account, the website or app first needs to be registered with via the Microsoft Entra ID app registration interface.- Log into the Azure Portal with an account that has permission to register app within Microsoft Entra ID
- Select “App Registration”
- Select ”+ New Registration”
- Enter a name for this application
- For “Supported account types” select “Personal Microsoft accounts only”
- Enter a redirect URL that you want the authentication flow to redirect the user to after successful authentication. Make note of this as you’ll need it later. You can add additional URIs later as well
- Complete the App registration
- Make note of the Application (client) ID and the Directory (tenant) ID
- Select Certificates & Secrets
- Select ”+ New Client Secret”
- Enter a Description
- Select an Expiration Range
- Click Add
- Make note of the created Client Secret value as you’ll need it later. This value should only be used and stored securely on your service.
Integration
Implementing the flow mentioned above, and using the identifiers created during the registration process implement the following:-
Begin the OAuth2.0 Flow by requesting an authorization code:
- Navigate the user to
https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize?client_id=[Application (client) ID from Registration]&response_type=code&redirect_uri=[RedirectUI given during registration]&scope=xboxlive.signin&xboxlive.offline_accessIn this example we are requesting a sign-in token and access to an offline token which can be used to refresh the access token after it expires. This will also show the correct account privacy and activity notices to the user. - Once the user completes logging into their Microsoft Account, they will be redirected to the redirect URI provided with the authorization code appended with the
"code="followed by the authorization code. - The use of
xboxlive.offline_accessscope is optional and only needed for scenarios that require calls after the original sign-in token has expired. Other, additional scopes cannot be used for this request.
- Navigate the user to
-
Redeem a Microsoft Account access token using the authorization code and the client secret generated during the application registration process:
- Create a POST web request with the following properties:
URL:
https://login.microsoftonline.com/consumers/oauth2/v2.0/tokenHeader:Content-Type: application/x-www-form-urlencodedBody:
- Create a POST web request with the following properties:
URL:
- The response from the service will contain a JSON response with the following information:
Token Type:
BearerScope:XboxLive.signin XboxLive.offline_accessExpires_in:ValueAccess_token:[token value]This is your access token which you’ll use to exchange with XBOX services for an XBOX User Token.
- You can request an XBOX User token by calling the XBOX authentication endpoints and exchange your Microsoft Account access token for an XBOX User Token by completing the following request:
- Create a POST web request with the following properties:
URL:
https://user.auth.xboxlive.com/user/authenticateHeader:x-xbl-contract-version: 1Header:content-type: application/jsonBody: A well formed json payload that includes following data:
- Create a POST web request with the following properties:
URL:
- The response from the service will contain a json payload containing the following information included the XBOX User Token. You will need the XBOX User Token in the next step:
- You can then exchange your User Token for an X-token. If you want to perform service-to-service calls on behalf of the user and need the DelegationToken claim or the XUID for the user you can request an X-token for your own Relying Party and then handle that token as you would normally to extract the needed claims.
