Skip to content

Adds support for custom url (ciam login) #364

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
86 changes: 43 additions & 43 deletions assets/msalv2.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,46 @@ var aadOauth = (function () {
};

// Initialise the myMSALObj for the given client, authority and scope
function init(config) {
// TODO: Add support for other MSAL configuration
var authData = {
clientId: config.clientId,
authority: config.isB2C ? "https://" + config.tenant + ".b2clogin.com/tfp/" + config.tenant + ".onmicrosoft.com/" + config.policy + "/" : "https://login.microsoftonline.com/" + config.tenant,
knownAuthorities: [ config.tenant + ".b2clogin.com", "login.microsoftonline.com"],
redirectUri: config.redirectUri,
};
var postLogoutRedirectUri = {
postLogoutRedirectUri: config.postLogoutRedirectUri,
};
var msalConfig = {
auth: config?.postLogoutRedirectUri == null ? {
...authData,
} : {
...authData,
...postLogoutRedirectUri,
},
cache: {
cacheLocation: config.cacheLocation,
storeAuthStateInCookie: false,
},
};

if (typeof config.scope === "string") {
tokenRequest.scopes = config.scope.split(" ");
} else {
tokenRequest.scopes = config.scope;
}

tokenRequest.extraQueryParameters = JSON.parse(config.customParameters);
tokenRequest.prompt = config.prompt;
tokenRequest.loginHint = config.loginHint;

myMSALObj = new msal.PublicClientApplication(msalConfig);
// Register Callbacks for Redirect flow and record the task so we
// can await its completion in the login API

redirectHandlerTask = myMSALObj.handleRedirectPromise();
}
function init(config) {
// TODO: Add support for other MSAL configuration
var authData = {
clientId: config.clientId,
authority: config.authorizationUrl,
knownAuthorities: [config.tenant + ".ciamlogin.com", config.tenant + ".b2clogin.com", "login.microsoftonline.com", config.tenant + ".onmicrosoft.com"],
redirectUri: config.redirectUri,
};
var postLogoutRedirectUri = {
postLogoutRedirectUri: config.postLogoutRedirectUri,
};
var msalConfig = {
auth: config?.postLogoutRedirectUri == null ? {
...authData,
} : {
...authData,
...postLogoutRedirectUri,
},
cache: {
cacheLocation: config.cacheLocation,
storeAuthStateInCookie: false,
},
};

if (typeof config.scope === "string") {
tokenRequest.scopes = config.scope.split(" ");
} else {
tokenRequest.scopes = config.scope;
}

tokenRequest.extraQueryParameters = JSON.parse(config.customParameters);
tokenRequest.prompt = config.prompt;
tokenRequest.loginHint = config.loginHint;

myMSALObj = new msal.PublicClientApplication(msalConfig);
// Register Callbacks for Redirect flow and record the task so we
// can await its completion in the login API

redirectHandlerTask = myMSALObj.handleRedirectPromise();
}

// Tries to silently acquire a token. Will return null if a token
// could not be acquired or if no cached account credentials exist.
Expand Down Expand Up @@ -92,7 +92,7 @@ var aadOauth = (function () {
extraQueryParameters: tokenRequest.extraQueryParameters
});

return authResult = silentAuthResult;
return authResult = silentAuthResult;
} catch (error) {
console.log('Unable to silently acquire a new token: ' + error.message)
return null;
Expand Down Expand Up @@ -122,7 +122,7 @@ var aadOauth = (function () {
// a cached access token
await silentlyAcquireToken()

if(authResult != null) {
if (authResult != null) {
// Skip interactive login
onSuccess(authResult.accessToken ?? null);
return
Expand Down Expand Up @@ -185,7 +185,7 @@ var aadOauth = (function () {
// a cached access token
await silentlyAcquireToken()

if(authResult != null) {
if (authResult != null) {
onSuccess(authResult.accessToken ?? null);
return
}
Expand Down