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

Smit Rathod 0 Reputation points
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
Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
4,324 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,383 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,206 questions
Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
2,759 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Akhilesh 7,230 Reputation points Microsoft Vendor
    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.