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

Login reloop issue when using msal-angular wrapper #5132

Closed
supriyaGannvi opened this issue Aug 25, 2022 · 35 comments
Closed

Login reloop issue when using msal-angular wrapper #5132

supriyaGannvi opened this issue Aug 25, 2022 · 35 comments
Assignees
Labels
answered Question has received "first qualified response" bug-unconfirmed A reported bug that needs to be investigated and confirmed msal-angular Related to @azure/msal-angular package msal-browser Related to msal-browser package Needs: Author Feedback Awaiting response from issue author no-issue-activity Issue author has not responded in 5 days public-client Issues regarding PublicClientApplications question Customer is asking for a clarification, use case or information.

Comments

@supriyaGannvi
Copy link

Core Library

MSAL.js v2 (@azure/msal-browser)

Core Library Version

2.14.1

Wrapper Library

MSAL Angular (@azure/msal-angular)

Wrapper Library Version

2.0.5

Public or Confidential Client?

Public

Description

@jasonnutter Using Angular Wrapper, after sometime when accessing the application, loginRedirect goes into loop then I have to delete cookies to make it work. What's the trick to make it work. it works fine for the first time. Appreciate your help.

Error Message

No response

Msal Logs

No response

MSAL Configuration

auth: {
      clientId: clientid
      authority: authority,
    
    },
    cache: {
      cacheLocation: BrowserCacheLocation.LocalStorage,
      storeAuthStateInCookie: isIE // set to true for IE 11. Remove this line to use Angular Universal
    },
    system: {
      loggerOptions: {
        loggerCallback,
        logLevel: LogLevel.Info,
        piiLoggingEnabled: false
      }
    }

Relevant Code Snippets

msalService.loginRedirect(singIn)

Reproduction Steps

  1. Logged in with properly user and did not logged out
  2. Logged in after 24 hrs and logging with different user
  3. The Application looping back to multiple time until the user explicitly delete the cookies

Expected Behavior

once user logs in after token expiry then it should navigate to authentication screen and once he logs in the user should be login with new token

Identity Provider

Azure AD / MSA

Browsers Affected (Select all that apply)

Edge

Regression

@azure/msal-browser: "2.19.0"

Source

Internal (Microsoft)

@supriyaGannvi supriyaGannvi added bug-unconfirmed A reported bug that needs to be investigated and confirmed question Customer is asking for a clarification, use case or information. labels Aug 25, 2022
@ghost ghost added the Needs: Attention 👋 Awaiting response from the MSAL.js team label Aug 25, 2022
@github-actions github-actions bot added msal-angular Related to @azure/msal-angular package msal-browser Related to msal-browser package public-client Issues regarding PublicClientApplications labels Aug 25, 2022
@ghost ghost assigned jo-arroyo Aug 25, 2022
@jo-arroyo
Copy link
Collaborator

@supriyaGannvi Are you able to provide verbose logs of this behavior?

@ghost ghost added answered Question has received "first qualified response" Needs: Author Feedback Awaiting response from issue author and removed Needs: Attention 👋 Awaiting response from the MSAL.js team labels Aug 25, 2022
@supriyaGannvi
Copy link
Author

133048223-36214e5e-5c39-46f7-82f3-a73ad2406dfa

@ghost ghost added Needs: Attention 👋 Awaiting response from the MSAL.js team and removed Needs: Author Feedback Awaiting response from issue author labels Aug 26, 2022
@supriyaGannvi
Copy link
Author

@jo-arroyo this is what we get console

@jo-arroyo
Copy link
Collaborator

@supriyaGannvi Please send verbose logs. You can turn on verbose logging by changing the logLevel in the configurations as follows:

auth: {
      clientId: clientid
      authority: authority,
    
    },
    cache: {
      cacheLocation: BrowserCacheLocation.LocalStorage,
      storeAuthStateInCookie: isIE
    },
    system: {
      loggerOptions: {
        loggerCallback,
        logLevel: LogLevel.Verbose, // Change to Verbose here
        piiLoggingEnabled: false
      }
    }

@ghost ghost added Needs: Author Feedback Awaiting response from issue author and removed Needs: Attention 👋 Awaiting response from the MSAL.js team labels Aug 26, 2022
@ionut-gheorghe
Copy link

I can confirm this. After the refresh token is expired (I have this issue that logs out the user even if the user has conditional access policies, 24 hours refresh token for SPA) and I try to log in the another user: redirects to the first user asking for password. You either have to delete the cookie or sign out the first user.

@supriyaGannvi
Copy link
Author

@ionut-gheorghe Did u got any solution for this issue

@ghost ghost added Needs: Attention 👋 Awaiting response from the MSAL.js team and removed Needs: Author Feedback Awaiting response from issue author labels Sep 1, 2022
@ionut-gheorghe
Copy link

ionut-gheorghe commented Sep 1, 2022

None for my 2 issues: mandatory interactive login after 24 hours and the loop when sign in a new user.

@supriyaGannvi
Copy link
Author

@jo-arroyo could u help us how can we reslove this issue

@jo-arroyo
Copy link
Collaborator

@ionut-gheorghe Needing to login interactively after 24 hours is expected behavior. Refresh tokens used in single page apps and with the authorization code flow are limited to 24 hours. Once outside the 24 hour window, it is supposed to fail and require interactive login. While we recognize that this is not the best user experience, the 24 hour limit was chosen for security reasons for single-page apps. Please see this document about refresh tokens lifetimes and this document about refresh tokens and the auth code flow.

@supriyaGannvi Please provide verbose logs, per above.

@ghost ghost added Needs: Author Feedback Awaiting response from issue author and removed Needs: Attention 👋 Awaiting response from the MSAL.js team labels Sep 1, 2022
@supriyaGannvi
Copy link
Author

supriyaGannvi commented Sep 2, 2022

Screenshot (62)

@ghost ghost added Needs: Attention 👋 Awaiting response from the MSAL.js team and removed Needs: Author Feedback Awaiting response from issue author labels Sep 2, 2022
@ghost ghost added the no-issue-activity Issue author has not responded in 5 days label Sep 22, 2022
@supriyaGannvi
Copy link
Author

@bmahall still the issue persist

@ghost ghost added Needs: Attention 👋 Awaiting response from the MSAL.js team and removed Needs: Author Feedback Awaiting response from issue author no-issue-activity Issue author has not responded in 5 days labels Sep 22, 2022
@supriyaGannvi
Copy link
Author

@bmahall We have added the $Inprogress and handle the active account as suggest by you still we could see the login redirect issue

@supriyaGannvi
Copy link
Author

@bmahall could u please helps us out

@bmahall
Copy link
Contributor

bmahall commented Sep 25, 2022

@supriyaGannvi Can you please share the fiddler trace and verbose logs on the email on my Git profile? Thanks

@ghost ghost added Needs: Author Feedback Awaiting response from issue author and removed Needs: Attention 👋 Awaiting response from the MSAL.js team labels Sep 25, 2022
@bmahall
Copy link
Contributor

bmahall commented Sep 25, 2022

@supriyaGannvi Meanwhile , please refer to a couple of points : -

  1. Are you able to reproduce the behavior with local Storage , rather than session storage?
  2. Please confirm the version(s) of msal-angular with which you are facing this issue
  3. Redirects must be handled either with the MsalRedirectComponent or with calling handleRedirectObservable(). See our docs on redirects here for more information. Additionally, any interaction or account validation should be done after subscribing to the inProgress$ observable and filtering for InteractionStatus.None.
    For more details on the above, please refer to the sample

Kindly share your source code wherein you are calling loginRedirect on my email.
Thanks for your patience!

@supriyaGannvi
Copy link
Author

this is snipped code

this.msalBrodcastService.msalSubject$
.pipe(
filter(
(msg: EventMessage) =>
msg.eventType === EventType.LOGIN_SUCCESS ||
msg.eventType === EventType.LOGOUT_START
)
)
.subscribe(({ eventType }: EventMessage) => {
if (eventType === EventType.LOGIN_SUCCESS) {
this._isAuthenticated.next(true);
} else {
this._isAuthenticated.next(false);
}
});

this.msalBrodcastService.inProgress$
  .pipe(filter((status: InteractionStatus) => status === InteractionStatus.None))
  .subscribe(() => {
    this.setLoginDisplay();
  });

}

/**

  • function to represent the login Disaply
    */
    setLoginDisplay = () =>
    (this.loginDisplay =
    this.authService.instance.getAllAccounts().length >
    DefaultNumberInitializableConstants.ZERO);

/**

  • Login using MSAL
  • @param popup Should the login happen using popup or redirect
  • @returns Observable with either void or AuthenticationResult
    */
    onLogin(popup: boolean = false): Observable<void | AuthenticationResult> {
    if (popup) {
    return this.authService.loginPopup();
    } else {
    return this.authService.loginRedirect();
    }
    }

@ghost ghost added Needs: Attention 👋 Awaiting response from the MSAL.js team and removed Needs: Author Feedback Awaiting response from issue author labels Sep 26, 2022
@bmahall
Copy link
Contributor

bmahall commented Sep 26, 2022

@supriyaGannvi Please use the following code in place of this.msalBrodcastService.inProgress$ .pipe(filter((status: InteractionStatus) => status === InteractionStatus.None)) .subscribe(() => { this.setLoginDisplay(); });

`
this.msalBroadcastService.inProgress$
.pipe(
filter((status: InteractionStatus) => status === InteractionStatus.None),
takeUntil(this._destroying$)
)
.subscribe(() => {
this.setLoginDisplay();
this.checkAndSetActiveAccount();
})
}

setLoginDisplay() {
this.loginDisplay = this.authService.instance.getAllAccounts().length > 0;
}

checkAndSetActiveAccount(){
/**
* If no active account set but there are accounts signed in, sets first account to active account
* To use active account set here, subscribe to inProgress$ first in your component
* Note: Basic usage demonstrated. Your app may require more complicated account selection logic
*/
let activeAccount = this.authService.instance.getActiveAccount();

if (!activeAccount && this.authService.instance.getAllAccounts().length > 0) {
  let accounts = this.authService.instance.getAllAccounts();
  this.authService.instance.setActiveAccount(accounts[0]);
}

}
`

@ghost ghost added Needs: Author Feedback Awaiting response from issue author and removed Needs: Attention 👋 Awaiting response from the MSAL.js team labels Sep 26, 2022
@supriyaGannvi
Copy link
Author

@bmahall we cannot add the $destory for the service

@ghost ghost added Needs: Attention 👋 Awaiting response from the MSAL.js team and removed Needs: Author Feedback Awaiting response from issue author labels Sep 27, 2022
@ghost
Copy link

ghost commented Oct 2, 2022

This issue requires attention from the MSAL.js team and has not seen activity in 5 days. @bmahall please follow up.

1 similar comment
@ghost
Copy link

ghost commented Oct 8, 2022

This issue requires attention from the MSAL.js team and has not seen activity in 5 days. @bmahall please follow up.

@tnorling tnorling assigned tnorling and unassigned bmahall Oct 10, 2022
@tnorling
Copy link
Collaborator

@bmahall we cannot add the $destory for the service

Why not? Can you also please confirm that you are handling the redirect response as described by @bmahall above? Are you able to reproduce your issue with one of our samples here?

@ghost ghost added Needs: Author Feedback Awaiting response from issue author and removed Needs: Attention 👋 Awaiting response from the MSAL.js team labels Oct 11, 2022
@ghost
Copy link

ghost commented Oct 17, 2022

@supriyaGannvi This issue has been automatically marked as stale because it is marked as requiring author feedback but has not had any activity for 5 days. If your issue has been resolved please let us know by closing the issue. If your issue has not been resolved please leave a comment to keep this open. It will be closed automatically in 7 days if it remains stale.

@ghost ghost added the no-issue-activity Issue author has not responded in 5 days label Oct 17, 2022
@ghost ghost closed this as completed Oct 24, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered Question has received "first qualified response" bug-unconfirmed A reported bug that needs to be investigated and confirmed msal-angular Related to @azure/msal-angular package msal-browser Related to msal-browser package Needs: Author Feedback Awaiting response from issue author no-issue-activity Issue author has not responded in 5 days public-client Issues regarding PublicClientApplications question Customer is asking for a clarification, use case or information.
Projects
None yet
Development

No branches or pull requests

5 participants