0

I need to obtain O365 token and send it back to API (.NET) to store in DB. after successful login or consent request - it redirects popup to localhost (that's what I configured in Azure as redirectURL). then popup stays there . If I close this popup - I get an error: user_cancelled: User cancelled the flow.

Here is what I tried: Option 1: App.module

MsalModule.forRoot(new PublicClientApplication({
      auth:{
        clientId:"my-client-id",
        authority:"https://login.microsoftonline.com/$my-tenant-id",
        redirectUri:'http://localhost',
        navigateToLoginRequestUrl:false //also tried set to true
      },
      cache: {
      cacheLocation: BrowserCacheLocation.LocalStorage //nothing gets in as request incomplete
      }
    }), 
    {
      interactionType: InteractionType.Popup, // MSAL Guard Configuration
    },
   null),

inside component:

  constructor(
    @Inject(MAT_DIALOG_DATA) public data: DialogOauthEditData,
    private eventManager: EventManagerService,
    private adminApi: AdminApiService,
    private authService: MsalService
  ) { }
  async signIn() {
const request: PopupRequest = {
        scopes : ["email",
                 "offline_access",
                 "https://outlook.office.com/SMTP.Send"],
                 prompt:'login', // also tried 'consent'      
      } 
      try {
        
        return await this.authService.acquireTokenPopup(request).subscribe(response => {console.log(response); this.authResult = response});
      } catch (error) {
        console.log(error);
      }

what I get is the error from microsoft: "AADSTS700016: Application with identifier 'UNKNOWN' was not found in the directory "

Option 2: instead of calling msalService

     let fakeService = new PublicClientApplication({
       auth:{
        clientId:"my-client-id",
        authority:"https://login.microsoftonline.com/$my-tenant-id",
        redirectUri:'http://localhost',
        navigateToLoginRequestUrl:false //also tried set to true
        
      }
     });

and then same:

        return await fakeService.acquireTokenPopup(request).then(response => {console.log(response); this.authResult = response});
      } catch (error) {
        console.log(error);
      }

this leads to popup redirect to localhost and stay there . close popup -> error: user_cancelled: User cancelled the flow.

also tried LoginPopup, loginrRedirect etc. - it always redirect to localhost , doesn't close popup and just stays there without returing the token

various MSAL config options, popup should close - token saved in var

Vladi
  • 1

0 Answers0