Share via

Get The Accounts That Have Been Signed In Already In MSAL (MAUI)

Anonymous
2024-07-08T16:54:36.2333333+00:00

Implementing MSAL in MAUI application.

Sign In process is created by using below snippet.

authenticationResult = await _identityClient
                        .AcquireTokenInteractive(AppSettings.MSALScopes)
                        .WithUseEmbeddedWebView(true)
                        .ExecuteAsync();

When the first time application opens, The user will see the MS Sign In page. After sign in, The user will be redirected to the 'MainPage' (HomePage).

When that signed in user close & re-opens the application, He must be directly redirected to the 'MainPage' (HomePage). For that, I have below code to check if user has already signed in.

public AuthService()
{
    _identityClient  = PublicClientApplicationBuilder.Create(AppSettings.MSALAzureClientId)
    .WithRedirectUri(AppSettings.MSALRedirectURI)
    .WithCacheOptions(CacheOptions.EnableSharedCacheOptions)
    .Build();
}

public async Task
Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | .NET | .NET MAUI
Microsoft 365 and Office | Install, redeem, activate | For business | Windows
Microsoft Security | Microsoft Entra | Microsoft Entra External ID
0 comments No comments

1 answer

Sort by: Most helpful
  1. Akhilesh Vallamkonda 15,355 Reputation points Moderator
    2024-07-09T11:08:23.17+00:00

    Hi @Smit Rathod

    I understand that you that you are implement MSAL in MAUI application and user must redirect to Main Page if signed in.

    To achieve this, it needs to attempt to acquire an access token for the account from the user token cache.

    Please follow the below documents for more information.

    ClientApplicationBase.AcquireTokenSilent Method
    Understanding the AcquireTokenAsync API

    Hope this helps. Do let us know if you any further queries.

    Thanks,

    Akhilesh.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.