CmlLib
English (v4)
English (v4)
  • 🧊CmlLib Projects
  • 🚀CmlLib.Core
    • Home
    • Getting Started
      • Minecraft Launcher
      • Minecraft Path
      • Versions
      • Launch Options
      • Event Handling
    • Login and Sessions
      • Microsoft Xbox Account
      • Offline Account
    • More APIs
      • MinecraftLauncherParameters
      • Rules
      • FileExtractor
      • GameInstaller
      • Java
    • Mod Loader Installers
      • Forge Installer
      • Fabric Installer
      • Quilt Installer
      • LiteLoader Installer
    • Utilities
      • Minecraft Changelogs
    • Resources
      • FAQ
      • Known Issues
      • Sample Launcher
      • License
  • 🔓Auth.Microsoft
    • Home
    • CmlLib.Core.Auth.Microsoft
      • JELoginHandler
      • JELoginHandlerBuilder
      • JEAuthenticator
      • Authentication with MSAL
    • XboxAuthNet.Game
      • OAuth
      • XboxAuth
      • XboxAuthException
      • AccountManager
      • Accounts
    • XboxAuthNet.Game.Msal
      • ClientID
      • MsalClientHelper
      • OAuth
    • CmlLib.Core.Bedrock.Auth
    • Resources
  • 🌐MojangAPI
    • Home
    • Mojang API
    • SecurityQuestion
  • ⚒️Installer.Forge
    • Home
    • Supported Versions
    • Getting Started
    • MForge
    • ForgeVersionLoader
Powered by GitBook
On this page
  • Register an OAuthProvider
  • Using AddMsalOAuth
Edit on GitHub
  1. Auth.Microsoft
  2. CmlLib.Core.Auth.Microsoft

Authentication with MSAL

PreviousJEAuthenticatorNextXboxAuthNet.Game

Last updated 9 months ago

JELoginHandler only works on Windows. To use it on another platform, you must use it with .

There are two ways to use CmlLib.Core.Auth.Microsoft with XboxAuthNet.Game.Msal.

  • Register an OAuthProvider when initializing JELoginHandler.

  • Create an IAuthenticator and add a MSAL authenticator.

Register an OAuthProvider

Register the OAuthProvider when initializing the JELoginHandler so that all subsequent methods you call will handle the login with the MSAL.

var app = await MsalClientHelper.BuildApplicationWithCache("CLIENT-ID");
var loginHandler = new JELoginHandlerBuilder()
    .WithOAuthProvider(new MsalCodeFlowProvider(app))
    .Build();
    
// login
var session = await loginHandler.Authenticate();

// add new account
var session = await loginHandler.AuthenticateInteractively();

// login with most recently logged in account
var session = await loginHandler.AuthenticateSilently();

// clear
await loginHandler.Signout();

// signout
await loginHandler.SignoutWithBrowser();

Using AddMsalOAuth

Authenticating with new account:

var app = await MsalClientHelper.BuildApplicationWithCache("CLIENT-ID");
var loginHandler = new JELoginHandlerBuilder()
    .Build();

// create authenticator with new account
var authenticator = loginHandler.CreateAuthenticatorWithNewAccount();
authenticator.AddMsalOAuth(app, msal => msal.Interactive());
authenticator.AddXboxAuthForJE(xbox => xbox.Basic());
authenticator.AddForceJEAuthenticator();
var session = await authenticator.ExecuteForLauncherAsync();

Authenticating with the most recent account:

var app = await MsalClientHelper.BuildApplicationWithCache("CLIENT-ID");
var loginHandler = new JELoginHandlerBuilder()
    .Build();

// create authenticator with the most recent account
var authenticator = loginHandler.CreateAuthenticatorWithDefaultAccount();
authenticator.AddMsalOAuth(app, msal => msal.Silent());
authenticator.AddXboxAuthForJE(xbox => xbox.Basic());
authenticator.AddJEAuthenticator();
var session = await authenticator.ExecuteForLauncherAsync();

Signout:

var app = await MsalClientHelper.BuildApplicationWithCache("CLIENT-ID");
var loginHandler = new JELoginHandlerBuilder()
    .Build();
    
var authenticator = loginHandler.CreateAuthenticatorWithDefaultAccount();
authenticator.AddMsalOAuth(app, msal => msal.ClearSession());
authenticator.AddXboxAuthSignout();
authenticator.AddJESignout();
var session = await authenticator.ExecuteForLauncherAsync();

For more information about loginHandler, see .

For more methods in MSAL, such as msal.Interactive(), msal.Silent(), and more, see .

🔓
XboxAuthNet.Game.Msal
JELoginHandler
OAuth