Skip to content

How to setup Microsoft Auth

dommilosz edited this page Apr 16, 2024 · 4 revisions

Setup for public client applications

Simpler, faster to setup, not requiring server handling the app secret. Valid only for 24 hours

const MicrosoftAuth = minecraftAuth.MicrosoftAuth;

let account = new minecraftAuth.MicrosoftAccount();
MicrosoftAuth.setup({appID:"74c5dc2a-449c-4224-8fe5-ca83ac47f48c"});

let pkce = MicrosoftAuth.generatePKCEPair();
let code = await MicrosoftAuth.listenForCode({pkcePair:pkce});

if(code !== undefined){
   await account.authFlow(code, pkce);
}

You need appID in order for it to work. You can use the provided one (only works with http://localhost:8080/token redirect url) or use your own one. In order to get it you need to:

  • Create azure application in App Registrations
  • Add single page app platform in Authentication tab
  • Add redirect url(s) for example: http://localhost:8080/token
  • Put this application id in the setup function.

image

Setup for web application

Requires server middleware that secures your app secret. Refresh tokens for web apps don't have specified lifetimes

const MicrosoftAuth = minecraftAuth.MicrosoftAuth;

let account = new minecraftAuth.MicrosoftAccount();
MicrosoftAuth.setup({appID:"YOUR APP ID", appSecret:"YOUR APP SECRET"});
let code = await MicrosoftAuth.listenForCode();

if(code !== undefined){
   await account.authFlow(code);
}
  • As with public client create app and note it's applictaion id.
  • In Certificates and Secrets tab create app secret.
  • Add web app platform in Authentication tab
  • Type in your redirect urls.
Clone this wiki locally