I am working on Angular 4.5 application and Azure B2C authentication work. I have separate app with my azure B2C configuration and is working so I know problem is in my code. I am getting error for Msal undefined.
I have install Msal library by
npm install msal
but I am not sure if I need to add reference to package.json file before or after installation??
The Visual Studio Code doesn't give me any error but at browser it does.
error
ReferenceError: 'Msal' is not defined
at MsalService (http://localhost:4000/0.chunk.js:15545:9)
at createClass (http://localhost:4000/main.bundle.js:11407:13)
at _createProviderInstance (http://localhost:4000/main.bundle.js:11380:13)
at createProviderInstance (http://localhost:4000/main.bundle.js:11214:5)
at createViewNodes (http://localhost:4000/main.bundle.js:12679:17)
at callViewAction (http://localhost:4000/main.bundle.js:13138:13)
at execComponentViewsAction (http://localhost:4000/main.bundle.js:13047:13)
at createViewNodes (http://localhost:4000/main.bundle.js:12716:5)
at callViewAction (http://localhost:4000/main.bundle.js:13138:13)
at execComponentViewsAction (http://localhost:4000/main.bundle.js:13047:13)
at createViewNodes (http://localhost:4000/main.bundle.js:12716:5)
at createRootView (http://localhost:4000/main.bundle.js:12584:5)
at callWithDebugContext (http://localhost:4000/main.bund
Msal Service where error generating;
import { Injectable } from '@angular/core';
declare var bootbox: any;
declare var Msal: any;
@Injectable()
export class MsalService{
access_token: string;
tenantConfig = {
tenant: 'mytenant.onmicrosoft.com',
clientID: 'my client id xxx',
signUpSignInPolicy: 'B2C_1_SiUpIn',
b2cScopes: ["http://myb2cscope/App/Read"]
};
authority = "https://login.microsoftonline.com/tfp/" + this.tenantConfig.tenant + "/" + this.tenantConfig.signUpSignInPolicy;
/* B2C SignIn SignUp Policy Configuration*/
clientApplication = new Msal.UserAgentApplication(
this.tenantConfig.clientID, this.authority,
function (errorDesc: any, token: any, error: any, tokenType: any) {
// Called after loginRedirect or acquireTokenPopup
}
);
public login(): void {
var _this = this;
this.clientApplication.loginPopup(this.tenantConfig.b2cScopes).then(function (idToken: any) {
_this.clientApplication.acquireTokenSilent(_this.tenantConfig.b2cScopes).then(
function (accessToken: any) {
_this.access_token = accessToken;
}, function (error: any) {
_this.clientApplication.acquireTokenPopup(_this.tenantConfig.b2cScopes).then(
function (accessToken: any) {
_this.access_token = accessToken;
}, function (error: any) {
bootbox.alert("Error acquiring the popup:\n" + error);
});
})
}, function (error: any) {
bootbox.alert("Error during login:\n" + error);
});
}
logout(): void {
this.clientApplication.logout();
};
isOnline(): boolean {
return this.clientApplication.getUser() != null;
};
getProduct(): string
{
return "12 Apples";
}
}
I am not sure if I am missing very obvious or if there is way to confirm my install Msal library is working????