Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for tenanted endpoint in Graph explorer. #568

Merged
merged 8 commits into from
Jun 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/app/services/graph-client/msal-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,32 @@ export function getSessionId() {
}
}

// get current uri for redirect uri purpose
// ref - https://github.com/AzureAD/microsoft-authentication-library-for
// -js/blob/9274fac6d100a6300eb2faa4c94aa2431b1ca4b0/lib/msal-browser/src/utils/BrowserUtils.ts#L49
function getCurrentUri(): string {
return window.location.href.split('?')[0].split('#')[0];
}

function getAuthority(): string {
// support for tenanted endpoint
const urlParams = new URLSearchParams(location.search);
let tenant = urlParams.get('tenant');

if (tenant === null) {
tenant = 'common';
}

return `https://login.microsoftonline.com/${tenant}/`;
}

export async function logIn(sessionId = ''): Promise<any> {

const loginRequest: AuthenticationParameters = {
scopes: defaultUserScopes,
authority: getAuthority(),
prompt: 'select_account',
redirectUri: window.location.href.toLowerCase(),
redirectUri: getCurrentUri().toLowerCase(),
extraQueryParameters: { mkt: geLocale }
};

Expand Down Expand Up @@ -97,6 +118,7 @@ export function logOutPopUp() {
export async function acquireNewAccessToken(scopes: string[] = []): Promise<any> {
const loginRequest: AuthenticationParameters = {
scopes,
authority: getAuthority(),
};
if (loginType === LoginType.Popup) {
try {
Expand Down