nayanAubie / msal_auth

A new Flutter plugin for Azure AD authentication.
MIT License
6 stars 11 forks source link

Multiple account PublicClientApplication could not be created for unknown reasons #17

Open waihanko opened 3 months ago

waihanko commented 3 months ago

I am getting error Multiple account PublicClientApplication could not be created for unknown reasons

MsalAuth msalAuth = await MsalAuth.createPublicClientApplication (
        clientId: aadLoginConfig.clientId,
        scopes: [
          "User.Read", "profile", "openid"
        ],
        androidConfig: AndroidConfig(
          configFilePath: 'assets/environments/msal_config.json',
          tenantId: aadLoginConfig.tenant,
        ),
        iosConfig: IosConfig(
            authority: 'https://login.microsoftonline.com/${aadLoginConfig.tenant}/oauth2/v2.0/authorize',
            authMiddleware: AuthMiddleware.msAuthenticator,
            tenantType: TenantType.entraIDAndMicrosoftAccount
        ),
      );
      MsalUser? user = await msalAuth.acquireToken();

MASL Config is

{
  "client_id": "39f8043a-2ab9-45eb-w123-a2e83b0ed918",
  "authorization_user_agent": "DEFAULT",
  "redirect_uri": "msauth://tech.abccompany.def.dev/nktyYiBP7iUVzc2p4QdgiyXcOpw%3D",
  "account_mode": "SINGLE",
  "broker_redirect_uri_registered": false,
  "authorities":
  [
    {
      "type": "AAD",
      "authority_url": "https://login.microsoftonline.com/common",
      "audience": {
        "type": "AzureADandPersonalMicrosoftAccount",
        "tenant_id": "common"
      }
    }
  ]
}
nayanAubie commented 2 months ago

You are not entering the scopes properly. Add it like => 'https://graph.microsoft.com/user.read' (same for profile and openID) and it should work.

celvinren commented 2 weeks ago

@waihanko Try to change "account_mode": "SINGLE" to "account_mode": "MULTIPLE".

This package uses IMultipleAccountPublicClientApplication rather than ISingleAccountPublicClientApplication.