Currently, I’m working on integrating Microsoft Authentication to Angular App. So, I’m following official documentation from Microsoft. Link to documentation.
According to that, I installed @azure/msal-angular and @azure/msal-browser. Then I imported those to src/app/app.module.ts like this.
- Here is the code of app.module.ts
// For Microsoft Authentication
import {
IPublicClientApplication,
PublicClientApplication,
BrowserCacheLocation,
LogLevel,
InteractionType,
} from '@azure/msal-browser';
import {
MSAL_INSTANCE,
MSAL_INTERCEPTOR_CONFIG,
MsalInterceptorConfiguration,
MSAL_GUARD_CONFIG,
MsalGuardConfiguration,
MsalBroadcastService,
MsalService,
MsalGuard,
MsalRedirectComponent,
MsalModule,
MsalInterceptor,
} from '@azure/msal-angular';
Next I will attach code of package.json
{
"name": "material",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"bundle:report": "source-map-explorer dist/**/*.js"
},
"private": true,
"dependencies": {
"-": "0.0.1",
"@angular-devkit/core": "9.0.2",
"@angular/animations": "^9.1.4",
"@angular/cdk": "^8.2.3",
"@angular/cli": "^9.1.7",
"@angular/common": "^9.0.1",
"@angular/compiler": "9.0.1",
"@angular/core": "^9.0.1",
"@angular/flex-layout": "^9.0.0-beta.29",
"@angular/forms": "9.0.1",
"@angular/http": "^7.2.16",
"@angular/material": "^8.2.3",
"@angular/platform-browser": "9.0.1",
"@angular/platform-browser-dynamic": "9.0.1",
"@angular/router": "9.0.1",
"@azure/msal-angular": "^3.0.13",
"@azure/msal-browser": "^3.10.0",
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.901.7",
"@angular/compiler-cli": "9.0.1",
"@angular/language-service": "9.0.1",
"@types/chartist": "^0.9.47",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "^2.0.8",
"@types/jquery": "^3.3.32",
"@types/node": "^12.11.1",
"protractor": "^7.0.0",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "3.7.5"
}
}
Error is :
ERROR in node_modules/@azure/msal-common/dist/index.d.ts:13:10 - error TS1005: 'from' expected.
13 export * as AuthToken from "./account/AuthToken";
~~
node_modules/@azure/msal-common/dist/index.d.ts:13:13 - error TS1005: ';' expected.
13 export * as AuthToken from "./account/AuthToken";
~~~~~~~~~
node_modules/@azure/msal-common/dist/index.d.ts:13:23 - error TS1005: ';' expected.
13 export * as AuthToken from "./account/AuthToken";
~~~~
node_modules/@azure/msal-common/dist/index.d.ts:13:28 - error TS1005: ';' expected.
13 export * as AuthToken from "./account/AuthToken";
~~~~~~~~~~~~~~~~~~~~~
node_modules/@azure/msal-common/dist/index.d.ts:20:10 - error TS1005: 'from' expected.
20 export * as AuthorityFactory from "./authority/AuthorityFactory";
~~
node_modules/@azure/msal-common/dist/index.d.ts:20:13 - error TS1005: ';' expected.
20 export * as AuthorityFactory from "./authority/AuthorityFactory";
~~~~~~~~~~~~~~~~
node_modules/@azure/msal-common/dist/index.d.ts:20:30 - error TS1005: ';' expected.
20 export * as AuthorityFactory from "./authority/AuthorityFactory";
~~~~
node_modules/@azure/msal-common/dist/index.d.ts:20:35 - error TS1005: ';' expected.
20 export * as AuthorityFactory from "./authority/AuthorityFactory";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@azure/msal-common/dist/index.d.ts:29:10 - error TS1005: 'from' expected.
29 export * as CacheHelpers from "./cache/utils/CacheHelpers";
~~
node_modules/@azure/msal-common/dist/index.d.ts:29:13 - error TS1005: ';' expected.
29 export * as CacheHelpers from "./cache/utils/CacheHelpers";
~~~~~~~~~~~~
node_modules/@azure/msal-common/dist/index.d.ts:29:26 - error TS1005: ';' expected.
29 export * as CacheHelpers from "./cache/utils/CacheHelpers";
~~~~
node_modules/@azure/msal-common/dist/index.d.ts:29:31 - error TS1005: ';' expected.
29 export * as CacheHelpers from "./cache/utils/CacheHelpers";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@azure/msal-common/dist/index.d.ts:84:10 - error TS1005: 'from' expected.
84 export * as AADServerParamKeys from "./constants/AADServerParamKeys";
~~
node_modules/@azure/msal-common/dist/index.d.ts:84:13 - error TS1005: ';' expected.
84 export * as AADServerParamKeys from "./constants/AADServerParamKeys";
~~~~~~~~~~~~~~~~~~
node_modules/@azure/msal-common/dist/index.d.ts:84:32 - error TS1005: ';' expected.
84 export * as AADServerParamKeys from "./constants/AADServerParamKeys";
~~~~
node_modules/@azure/msal-common/dist/index.d.ts:84:37 - error TS1005: ';' expected.
84 export * as AADServerParamKeys from "./constants/AADServerParamKeys";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@azure/msal-common/dist/index.d.ts:88:10 - error TS1005: 'from' expected.
88 export * as TimeUtils from "./utils/TimeUtils";
~~
node_modules/@azure/msal-common/dist/index.d.ts:88:13 - error TS1005: ';' expected.
88 export * as TimeUtils from "./utils/TimeUtils";
~~~~~~~~~
node_modules/@azure/msal-common/dist/index.d.ts:88:23 - error TS1005: ';' expected.
88 export * as TimeUtils from "./utils/TimeUtils";
~~~~
node_modules/@azure/msal-common/dist/index.d.ts:88:28 - error TS1005: ';' expected.
88 export * as TimeUtils from "./utils/TimeUtils";
~~~~~~~~~~~~~~~~~~~
node_modules/@azure/msal-common/dist/index.d.ts:89:10 - error TS1005: 'from' expected.
89 export * as UrlUtils from "./utils/UrlUtils";
~~
node_modules/@azure/msal-common/dist/index.d.ts:89:13 - error TS1005: ';' expected.
89 export * as UrlUtils from "./utils/UrlUtils";
~~~~~~~~
node_modules/@azure/msal-common/dist/index.d.ts:89:22 - error TS1005: ';' expected.
89 export * as UrlUtils from "./utils/UrlUtils";
~~~~
node_modules/@azure/msal-common/dist/index.d.ts:89:27 - error TS1005: ';' expected.
89 export * as UrlUtils from "./utils/UrlUtils";
~~~~~~~~~~~~~~~~~~
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
I have removed some unnecessary codes from this to make these codes more clear.
I tried this solution in Stackoverflow. But could not fix it. I need to clarify this error and need to know how to fix or avoid this. Thank you 🙂
2
Answers
I fixed the issue. The problem is we can not use MSAL Version 03 with Angular 9. So I installed MSAL packages - version 2 and now it's working.
I followed this MS DOC, changed the app-routing.module.ts and auth-config.ts codes as given below. I successfully logged in with the Azure B2C tenant.
Use the commands below to create the Angular project and install the msal and material packages.
Note: The styles.css code from the above MS DOC gives errors. As it is optional, I didn’t use it in my Angular project.
Code :
src/app/app-routing.module.ts :
src/app/auth-config.ts :
package.json :
I added the Angular output URL in the B2C app Authentication as below.
I enabled the scope for the B2C tenant as below.
I granted openid, offline_access, and the (scope) tasks.read in B2C app API permissions as below.
Output :
The following Angular project ran successfully, as shown below:
Browser output :
I received the output below in the browser with the Angular output URL. Then, I clicked on the Login button, as shown below:
I entered my account details for login and clicked on the Sign in button, as shown below:
After successfully logging in, I clicked on Profile, as shown below:
I viewed my profile details and clicked on Web API, as shown below:
I saw the following in the Web API and clicked on the Logout button to log out, as shown below.