Created
October 6, 2020 12:16
-
-
Save StefanRiedmann/ca6f5da160dba087ed994a3ef35cb861 to your computer and use it in GitHub Desktop.
To generate a URL for making an OAuth login with Microsoft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Generate the redirect URL for a user to login with a Microsoft account. | |
* - The clientId is the id of the Active Directory application. | |
* - The redirect URL must be configured in that application (https!) | |
* - If an email is given, it will be preselected in the login box. | |
*/ | |
getMsOauthUrl(clientId: string, redirect: string, state: string, email?: string): string | |
{ | |
let url = `https://login.microsoftonline.com/common/oauth2/v2.0/authorize?` + | |
`client_id=${clientId}` + | |
'&response_type=code' + | |
`&redirect_uri=${encodeURI(redirect)}` + | |
'&scope=User.Read' + | |
'&response_mode=query' + | |
'&state=' + state; | |
if (email) | |
{ | |
url = `${url}&login_hint=${encodeURI(email)}&prompt=login`; | |
} | |
else | |
{ | |
url = `${url}&prompt=select_account`; | |
} | |
return url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment