How to silently redirecting the browser to the redirect Uri to avoid authentication pop up (AAD)

Viewed 421

We are working on a project where we are authenticating users with Azure Active Directory. Upon the successful authentication, the user's browsers receive an Id and Access token, and then we use the same access token to query other Microsoft products (Sharepoint, OneDrive, etc).

We also have to authenticate our users with Elastic Search when they try to search for something on our application. For that, We set up an elastic OIDC realm on the elastic search cluster and authenticating our users with it using a custom web app as a Relying Party. In simple words, the same user which was successfully authenticated earlier is asked to authenticate again in elastic by redirecting the browser to the redirect Uri (dataset1**) that is sent back to AAD. However, when the redirection is done in the user’s browser, the authentication pop-up comes up again and the client has to select the username to get the response. However, an access token is picked up from the cache storage and the password is not requested again.

Is there a way to avoid opening the Microsoft authentication page (second time) and get the token silently? We are fine with redirecting the user to the authentication page but it should not ask the users to click on their user name and should return back to the application with the token.

dataset1**

Redirect URI - https://login.microsoftonline.com/{tenant-Id}/oauth2/v2.0/authorize?scope=openid+email&response_type=code&redirect_uri=https://localhost:4200&state=lPk4uPPPMm0_LKgEmavga7p-cQSlMn8Ikz3PSvRIicQ&nonce=3CKNjofS_0Fh1j_Z9iwHztrjx-BP4DrgTAC8dKmyQKA&client_id=bb842c64-093c-40d0-a62f-13cc0a0cbcb1

Here is my angular code which redirects the user to redirect uri –

  AuthenticateElastic(): void {
    this.azureFunctionService.PrepElastic()
      .subscribe((authenticationResponse: any) => {
        this.dataShareService.setstate(authenticationResponse.state);
        this.dataShareService.setnonce(authenticationResponse.nonce);
        **document.location.href = authenticationResponse.redirect;**
      });
  }

The redirect URI which is shared above dataset1** is set for document.location.href which redirects the user browser and authentication popup comes up again. document.location.href = authenticationResponse.redirect;

2 Answers

Client to ask the authorization server, show or do not show a login and / or consent screen

GET /authorize?...&prompt={none}&

none - no show login or consent

The prompt=none parameter causes Auth0 to immediately send a result to the specified redirect_uri (callback URL) using the specified response_mode with one of two possible responses: success or error.

enter image description here

Optional Scenario:

You may want to avoid prompting the user for Multi-factor Authentication (MFA) each time they log in from the same browser. To do this, set up a rule so that MFA occurs only once per session. This is useful when performing silent authentication (prompt=none) to renew short-lived Access Tokens in a SPA during the duration of a user's session without having to rely on setting allowRememberBrowser to true.

Reference : Configure Silent Authentication (auth0.com)

Related