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

Enhancement/error hints #1060

Merged
merged 15 commits into from
Aug 27, 2021
Merged

Enhancement/error hints #1060

merged 15 commits into from
Aug 27, 2021

Conversation

Onokaev
Copy link
Contributor

@Onokaev Onokaev commented Aug 17, 2021

Overview

Solves the following authentication errors: null_or_empty_id_token,authorization_code_missing_from_server_response, no_tokens_found, invalid_request, user_login_error,nonce_mismatch_error, login_progress_error, interaction_in_progress,
'interaction_required, invalid_grant, endpoints_resolution_error, monitor_window_timeout.

Shows the user hints in case of common user mistakes like cancelling authentication popups, more information when scope consent is blocked and general hints on what to do when an authentication error occurs.

Demo

image
Notice the tip displayed after a user cancels the popup

image
Error and hint when a user cancels the auth consent on the auth pop-up window

Notes

Users might still get the authentication errors when signing in, but will not be blocked. Retrying a sign-in for the second time succeeds.

Testing Instructions

-Try signing in then cancel the window pop-up. A hint will be displayed on a messagebar on what to do.

-Sign in with your account and cancel the consent process or close the pop-up window. A hint will be displayed on what to do.

@github-actions
Copy link
Contributor

Azure Static Web Apps: Your stage site is ready! Visit it here: https://jolly-sand-0ac78c710-1060.centralus.azurestaticapps.net

Message: `Authentication failed: ${errorCode ? errorCode.replace('_', ' ') : ''}`,
});
Message: `Authentication failed: ${
errorCode ? errorCode.replace('_', ' ') : ''
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will replace only the first occurrence of the _ character. Try doing it like this

Suggested change
errorCode ? errorCode.replace('_', ' ') : ''
errorCode ? errorCode.replace(/_/g, ' '): ''

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Let me fix that

Comment on lines 87 to 89
const deleteHomeAccountId = () : void => {
localStorage.removeItem(HOME_ACCOUNT_KEY);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method has already been declared in the modules\authentication\AuthenticationWrapper.ts file as a private method. Changing it to a public function enables access to it from outside of the class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. Let me fix this also

<FormattedMessage id={`Signing you ${loginInProgress ? 'in' : 'out'}...`} />
</Label>}
</div>;
const getErrorAndHint = (errorCode: string): string => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A function should do one thing only. Consider breaking down the functionalities here so that the getErrorAndHint() function gets the error with the hint (if a hint exists) and clearing the cache happens in an appropriately named function that is called elsewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Let me break it down.

Comment on lines 146 to 151
for(const errorItem of AuthErrorList){
if( errorItem.trim() === errorCode.trim() ){
return true;
}
}
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could give the same result

Suggested change
for(const errorItem of AuthErrorList){
if( errorItem.trim() === errorCode.trim() ){
return true;
}
}
return false;
return AuthErrorList.includes(errorCode.trim());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I've seen it. Shorter and cleaner. Let me fix this also

@@ -20,6 +20,6 @@ export function getLoginType(): LoginType {
* -js/blob/9274fac6d100a6300eb2faa4c94aa2431b1ca4b0/lib/msal-browser/src/utils/BrowserUtils.ts#L49
*/
export function getCurrentUri(): string {
const currentUrl = window.location.href.split('?')[0].split('#')[0];
return currentUrl.toLowerCase();
const currentUrl = window.location.href.split('?')[0].split('#')[0] + 'blank.html';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: what is the effect of adding the blank.html to the URL?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/errors.md#monitor_window_timeout

We will no longer be getting monitor_window_timeout errors according to the msal documentation. I could use your input on this

Comment on lines 191 to 199
if(this.checkIfAuthResultError(errorCode) && !this.consentingToNewScopes){
this.clearCache();
this.deleteHomeAccountId();
window.sessionStorage.clear();
this.eraseInteractionInProgressCookie();
const result = await msalApplication.loginPopup(popUpRequest);
this.storeHomeAccountId(result.account!);
return result;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Check the indentation in this section

suggestion: There is a chance for a situation where the user will be in a popup loop since the error doesn't self resolve if the app tries to re-request a login popup. It could be safer to throw the error after clearing the cache since the user will get a hint about what went wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea. I missed that. I'll throw the error after clearing the cache.

window.sessionStorage.clear();
}
}
return errorCode.replace('_', ' ') + ' ' + translateMessage('Tip') + ': ' + errorMessageHint;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return the tip message if the error message hint exists

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me add a check for that also. Nice observation

@@ -115,7 +115,7 @@ export function consentToScopes(scopes: string[]): Function {
dispatch(
setQueryResponseStatus({
statusText: translateMessage('Scope consent failed'),
status: errorCode,
status: errorCode + ' ' + translateMessage('Tip') + ': ' + translateMessage('Access to permission denied'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Is this the only situation that consenting to permissions fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are two situations. The first one is an authentication error (access_denied) when a user is signing in to GE for the first time : If the user's tenant admin has restricted consent to client applications, they'll get the access denied error (Authentication failed: access_denied)
image

The second one is when a user is signed in to GE but they cannot consent to certain permissions because the tenant admin has blocked that. For this case, the user gets a 'Scope consent failed: access_denied
image

Is there a different scenario I have left out?

@github-actions
Copy link
Contributor

Azure Static Web Apps: Your stage site is ready! Visit it here: https://jolly-sand-0ac78c710-1060.centralus.azurestaticapps.net

@Onokaev Onokaev requested a review from thewahome August 19, 2021 15:04
@github-actions
Copy link
Contributor

Azure Static Web Apps: Your stage site is ready! Visit it here: https://jolly-sand-0ac78c710-1060.centralus.azurestaticapps.net

1 similar comment
@github-actions
Copy link
Contributor

Azure Static Web Apps: Your stage site is ready! Visit it here: https://jolly-sand-0ac78c710-1060.centralus.azurestaticapps.net

package.json Outdated
@@ -6,7 +6,7 @@
"@azure/msal-browser": "2.12.0",
"@babel/core": "7.12.13",
"@babel/eslint-parser": "7.12.13",
"@fluentui/react": "8.28.0",
"@fluentui/react": "^8.28.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this one at a constant.. So we can remove ^

@@ -6,4 +6,5 @@ export interface IStatus {
status: number;
statusText: string;
duration?: number;
hint?: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NICE!!

@github-actions
Copy link
Contributor

Azure Static Web Apps: Your stage site is ready! Visit it here: https://jolly-sand-0ac78c710-1060.centralus.azurestaticapps.net

@github-actions
Copy link
Contributor

Azure Static Web Apps: Your stage site is ready! Visit it here: https://jolly-sand-0ac78c710-1060.centralus.azurestaticapps.net

@thewahome thewahome linked an issue Aug 26, 2021 that may be closed by this pull request
@github-actions
Copy link
Contributor

Azure Static Web Apps: Your stage site is ready! Visit it here: https://jolly-sand-0ac78c710-1060.centralus.azurestaticapps.net

@github-actions
Copy link
Contributor

Azure Static Web Apps: Your stage site is ready! Visit it here: https://jolly-sand-0ac78c710-1060.centralus.azurestaticapps.net

@Onokaev Onokaev merged commit ce8439a into dev Aug 27, 2021
thewahome added a commit that referenced this pull request Sep 1, 2021
* Feature: Highlights the previously selected query (#1006)

* Task: upgrade packages flagged by dependabot (#1054)

* Task: Fluent upgrade (#1056)

* Fix: ProfileType persistence (#1074)

* Enhancement: error hints (#1060)

* Bug: Persisting request body (#1055)

* Fix: Sample queries UI bugs (#1084)

* Fix: Disable aria-required children rule (#1080)

* Task: Fix failing profile test (#1086)

* Enhancement: permissions radio buttons change (#1087)

* Task: add English file transfer automation (#1075)
@thewahome thewahome deleted the enhancement/error-hints branch September 9, 2021 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Authentication failed - interaction in progress
2 participants