microsoftgraph / microsoft-graph-toolkit

Authentication Providers and UI components for Microsoft Graph 🦒
https://docs.microsoft.com/graph/toolkit/overview
Other
937 stars 297 forks source link

[BUG] Issue with the Login component using the ElectronProvider #1649

Closed diptanu143 closed 7 months ago

diptanu143 commented 2 years ago

Describe the bug While using the ElectronProvider using the sample repo for typescript electron boilerplate, I get an error as below. Attaching some screenshots as well for reference. Appreciate some help on understanding what is going wrong.

My app registration is quite simple as per the steps explained here - https://docs.microsoft.com/en-us/graph/toolkit/providers/electron

Error in execution - Error occurred in handler for 'login': ClientAuthError: request_cannot_be_made: Token request cannot be made without authorization code or refresh token. at ClientAuthError.AuthError [as constructor] (webpack://electron-app-mgt/./node_modules/@azure/msal-common/dist/error/AuthError.js?:34:24) at new ClientAuthError (webpack://electron-app-mgt/./node_modules/@azure/msal-common/dist/error/ClientAuthError.js?:209:28) at Function.ClientAuthError.createTokenRequestCannotBeMadeError (webpack://electron-app-mgt/./node_modules/@azure/msal-common/dist/error/ClientAuthError.js?:322:16) at AuthorizationCodeClient.eval (webpack://electron-app-mgt/./node_modules/@azure/msal-common/dist/client/AuthorizationCodeClient.js?:83:106) at step (webpack://electron-app-mgt/./node_modules/@azure/msal-common/dist/_virtual/_tslib.js?:83:23) at Object.eval [as next] (webpack://electron-app-mgt/./node_modules/@azure/msal-common/dist/_virtual/_tslib.js?:64:53) at eval (webpack://electron-app-mgt/./node_modules/@azure/msal-common/dist/_virtual/_tslib.js?:57:71) at new Promise () at __awaiter (webpack://electron-app-mgt/./node_modules/@azure/msal-common/dist/_virtual/_tslib.js?:53:12) at AuthorizationCodeClient.acquireToken (webpack://electron-app-mgt/./node_modules/@azure/msal-common/dist/client/AuthorizationCodeClient.js?:76:76) { errorCode: 'request_cannot_be_made', errorMessage: 'Token request cannot be made without authorization code or refresh token.', subError: '' }

App registration image

ghost commented 2 years ago

Hello diptanu143, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

diptanu143 commented 2 years ago

@musale where is the solution in #1648 ?

musale commented 2 years ago

@musale where is the solution in #1648 ?

Still triaging. The solution for this should also fix #1648. Are they different according to you?

diptanu143 commented 2 years ago

no they are same but I see both the issues are closed.. Hence worried..

musale commented 2 years ago

no they are same but I see both the issues are closed.. Hence worried..

This one is open :) I can't reproduce your bug @diptanu143. Do you have an idea which component throws the error during rendering? You can comment out each of the sample components in the <body> tag. Then uncomment one by one. I want to know what calls are being made that throw the error.

danieljaguiar commented 2 years ago

I can repro this!

node:electron/js2c/renderer_init:57 Uncaught (in promise) Error: Error invoking remote method 'login': ClientAuthError: request_cannot_be_made: Token request cannot be made without authorization code or refresh token. at EventEmitter.o.invoke (node:electron/js2c/renderer_init:57:526)

the component is Login from '@microsoft/mgt-react';

danieljaguiar commented 2 years ago

I have 2 tenants, one with MFA and other without.

@diptanu143 , I could fix in the tenant without MFA by adding the authority to MsalElectronConfig:

const config: MsalElectronConfig = {
    clientId: 'xxxxx', // xxxx = Application ID (UUID)
    mainWindow: newWindow,
    authority: 'https://login.microsoftonline.com/yyy', // yyy = Tenant UUID
    scopes: ['user.read'],
  };

@musale For my Tenant with MFA enabled, this is still a mystery!

diptanu143 commented 1 year ago

@danieljaguiar - i dont have MFA but it still doesnt work

musale commented 1 year ago

@diptanu143 @danieljaguiar sorry for the late update. We have released v3.0.0 now and you can test and see if this issue is still happening.

microsoft-github-policy-service[bot] commented 1 year ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

microsoft-github-policy-service[bot] commented 1 year ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

diptanu143 commented 1 year ago

@musale Unfortunately, I still get an error but a different one now -

image

image

musale commented 1 year ago

@diptanu143 what provider are you using? It's recommended to use Msal2Provider.

sebastienlevert commented 7 months ago

Enhancements are happening with v4, including a new Electron Provider! You can test if by installing our @next packages! Closing this issue for now but feel free to reach out if you have any questions and re-open it!