OAuth

Describes a way to proceed with Microsoft OAuth via MSAL.

You MUST initialize an IPublicClientApplication via YOUR CLIENT ID before to use this!

Example

JELoginHandler with MSAL OAuth.

using XboxAuthNet.Game.Msal;

var app = await MsalClientHelper.BuildApplicationWithCache("<CLIENT-ID>");
var loginHandler = JELoginHandlerBuilder.BuildDefault();

var authenticator = loginHandler.CreateAuthenticatorWithNewAccount(default);
authenticator.AddMsalOAuth(app, msal => msal.Interactive());
authenticator.AddXboxAuthForJE(xbox => xbox.Basic());
authenticator.AddJEAuthenticator();
var session = await authenticator.ExecuteForLauncherAsync();

Interactive

authenticator.AddMsalOAuth(app, msal => msal.Interactive());

Requests users to enter their Microsoft account. How the sign-in page is displayed is determined by the MSAL.

EmbeddedWebView

authenticator.AddMsalOAuth(app, msal => msal.EmbeddedWebView());

Prompts the user to enter their Microsoft account. Use WebView2 to display the login page.

SystemBrowser

authenticator.AddMsalOAuth(app, msal => msal.SystemBrowser());

Prompts the user to enter their Microsoft account. Open the system's default browser to display the sign-in page.

Silent

authenticator.AddMsalOAuth(app, msal => msal.Silent());

Attempts to sign in using the account information cached in the MSAL.

DeviceCode


authenticator.AddMsalOAuth(app, msal => msal.DeviceCode(deviceCode =>
{
    Console.WriteLine(deviceCode.Message);
    return Task.CompletedTask;
}));

Attempt to sign in using the DeviceCode method. This method doesn't require a web browser or UI on the client, but it does allow the client to log in from a different device.

If you're building a launcher that only works on the console or no GUI environment, use this method for login. The login can be done on a completely different device than the one running your launcher. For example, a user can log in from their mobile phone.

The example code outputs the following message to the console:

To sign in, use a web browser to open the page https://www.microsoft.com/link and enter the code XXXXXXXX to authenticate.

FromResult

var result = await app.AcquireTokenInteractive(MsalClientHelper.XboxScopes).ExecuteAsync();
authenticator.AddMsalOAuth(app, msal => msal.FromResult(result));

Use MSAL authentication result.

Last updated