AzureAD / microsoft-authentication-library-for-js

Microsoft Authentication Library (MSAL) for JS
http://aka.ms/aadv2
MIT License
3.66k stars 2.65k forks source link

uninitialized_public_client_application in acquireTokenRedirect method #6794

Closed oolaoluwa closed 9 months ago

oolaoluwa commented 10 months ago

Core Library

MSAL.js (@azure/msal-browser)

Core Library Version

3.6.0

Wrapper Library

Not Applicable

Wrapper Library Version

None

Public or Confidential Client?

Public

Description

Running into an uninitialized_public_client_application error when trying to authenticate for the Azure SDK.

Error Message

uninitialized_public_client_application: You must call and await the initialize function before attempting to call any other MSAL API. For more visit: aka.ms/msaljs/browser-errors createBrowserAuthError   node_modules/@azure/msal-browser/dist/error/BrowserAuthError.mjs:274:12  blockAPICallsBeforeInitialize   node_modules/@azure/msal-browser/dist/utils/BrowserUtils.mjs:130:98  StandardController.handleRedirectPromise   node_modules/@azure/msal-browser/dist/controllers/StandardController.mjs:190:96  PublicClientApplication.handleRedirectPromise   node_modules/@azure/msal-browser/dist/app/PublicClientApplication.mjs:211:32  MSALAuthCode.handleRedirect   node_modules/@azure/identity/dist-esm/src/msal/browserFlows/msalAuthCode.js:106:57  MSALAuthCode.getToken   node_modules/@azure/identity/dist-esm/src/msal/browserFlows/msalBrowserCommon.js:87:20  eval   node_modules/@azure/identity/dist-esm/src/credentials/interactiveBrowserCredential.browser.js:75:34  eval   node_modules/@azure/core-tracing/dist-esm/src/tracingClient.js:39:114  Object.withContext   node_modules/@azure/core-tracing/dist-esm/src/instrumenter.js:44:20  withContext   node_modules/@azure/core-tracing/dist-esm/src/tracingClient.js:52:81

Msal Logs

No response

MSAL Configuration

{
    "auth": {
        "clientId": "3cbcded7-0049-4401-9e00-5f4f10f75efe",
        "authority": "https://login.microsoftonline.com/72f988bf-86f1-41af-91ab-2d7cd011db47",
        "knownAuthorities": [],
        "redirectUri": "https://reactblade-ms.portal.azure.net"
    },
    "cache": {
        "cacheLocation": "sessionStorage",
        "storeAuthStateInCookie": true
    },
    "system": {
        "loggerOptions": {
            "logLevel": 3
        }
    }
}

Relevant Code Snippets

import { DevCenterClient } from "@azure/arm-devcenter";
import { InteractiveBrowserCredential } from "@azure/identity";

const resourceGroupName = "ajaykn"
const devCenterName = "ajaykn-dc";
const credential = new InteractiveBrowserCredential({clientId: "9fc8264d-0a40-4790-86e1-e7b73a2d2298", tenantId: "72f988bf-86f1-41af-91ab-2d7cd011db47" });
const client = new DevCenterClient(credential, subscriptionId);
const resArray = new Array();
for await (let item of client.images.listByDevCenter(resourceGroupName, devCenterName)) {
  resArray.push(item);
}
console.log(resArray)

Reproduction Steps

import { DevCenterClient } from "@azure/arm-devcenter"; import { InteractiveBrowserCredential } from "@azure/identity";

const resourceGroupName = "ajaykn" const devCenterName = "ajaykn-dc"; const credential = new InteractiveBrowserCredential({clientId: "9fc8264d-0a40-4790-86e1-e7b73a2d2298", tenantId: "72f988bf-86f1-41af-91ab-2d7cd011db47" }); const client = new DevCenterClient(credential, subscriptionId); const resArray = new Array(); for await (let item of client.images.listByDevCenter(resourceGroupName, devCenterName)) { resArray.push(item); } console.log(resArray)

Expected Behavior

Browser user is authenticated and client runs successfully- able to retrieve images from dev center

Identity Provider

Azure AD / MSA

Browsers Affected (Select all that apply)

Chrome, Edge

Regression

No response

Source

Internal (Microsoft)

hectormmg commented 10 months ago

@oolaoluwa this issue belongs on the Azure SDK repo given that there is no direct MSAL usage to investigate here. Please open an issue there. Thanks.

KarishmaGhiya commented 10 months ago

@hectormmg This bug is coming from the msal-browser library. The Azure SDK for Identity only acts like a wrapper library in this scenario. I will provide a repro with just using the msal-browser library if you'd like.

KarishmaGhiya commented 9 months ago

@oolaoluwa Please follow this https://github.com/Azure/azure-sdk-for-js/issues/28215 for your fix and feel free to reply on that issue thread. We have the bug fix released in the nightly build of @azure/identity library, which you can try out on your end. We'll be releasing the official fix early next week.

hectormmg commented 9 months ago

@KarishmaGhiya thanks for the update, closing this issue since the fix is shipping in @azure/identity library.

KarishmaGhiya commented 9 months ago

@oolaoluwa In case you missed, @azure/identity has shipped the fix for this in 3.4.2 and 4.0.1