I tried to implement msal to my react project. When I use localhost:3000 on msalIntance auth redirectUri, works perfectly. A popup appears and I can log into the application. The problem is when I put a https on the redirectUri. A popup appears and when I try to log in, the same page of redirectUri appears inside the popup. I already gave permissions of those the urls on azure portal. Some times, I don't know why I can logged in, and then, I try to replicate on incognito mode, and appears the problem that I mencioned before. Any help will be appreciated! thanks!
import { PublicClientApplication } from "@azure/msal-browser";
export interface MicrosoftServiceInterface {
getMicrosoftAccessToken(): Promise<string>;
refreshMicrosoftAccessToken(): Promise<string>;
}
export class MicrosoftServiceImpl implements MicrosoftServiceInterface {
private msalInstance = new PublicClientApplication({
auth: {
clientId: <client_id>,
authority: "https://login.microsoftonline.com/common",
redirectUri: "https://app.gaddex.es",
},
cache: {
cacheLocation: "sessionStorage", // This configures where your cache will be stored
storeAuthStateInCookie: false, // Set this to "true" if you are having issues on IE11 or Edge
},
});
// I think the problem is here //
getMicrosoftAccessToken(): Promise<string> {
return new Promise<string>((resolve, reject) => {
this.msalInstance.handleRedirectPromise();
this.msalInstance
.loginPopup({
scopes: ["User.Read"],
prompt: "select_account",
})
.then(({ accessToken }) => {
resolve(accessToken);
})
.catch((error) => {
reject(error);
});
});
}
refreshMicrosoftAccessToken(): Promise<string> {
const accounts = this.msalInstance.getAllAccounts();
if (accounts.length === 0) {
return Promise.reject("No accounts found");
} else {
return new Promise<string>((resolve, reject) => {
this.msalInstance
.acquireTokenSilent({
scopes: ["User.Read"],
account: accounts[0],
})
.then((result) => {
resolve(result.accessToken);
})
.catch((error) => {
reject(error);
});
});
}
}
}