benbaran / msal-angular

Angular MSAL Wrapper Module
MIT License
16 stars 16 forks source link
angular msal npm

msal-angular

This is a wrapper module to authenticate Angular applications to the Azure v2 endpoint. A working example can be found at: https://github.com/benbaran/msal-angular-example .

Change Log

2.0.2

BREAKING CHANGES:

2.0.1

1.0.X

Usage

Register your Application on the App Registration Portal

  1. Create a new app at apps.dev.microsoft.com
  2. Add the Web platform for your app
  3. Set the Redirect URI - for Angular CLI development this will be https://localhost:4200/
  4. Enable Allow Implicit Flow
  5. Copy the Application Id for use in the configuration

Install the NPM Module

npm install msal-angular --save

Usage in Angular CLI Application

1. Import MsalModule into app.module.ts:

@NgModule({
  imports: [MsalModule.forRoot({
      clientID: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
      graphScopes: ["openid"],
      authority: 'https://login.microsoftonline.com/<tenant>.onmicrosoft.com'
    })]
  })
  export class AppModule { }

2. Add Login, Logout Methods to Your Component:

  constructor(private msalService: MsalService) { }

  login() {
    this.msalService.login();
  }

  logout() {
    this.msalService.logout();
  }

  get authenticated(): Promise<boolean> {
    return this.msalService.authenticated;
  }

3. Config

* signUpSignInPolicy and tenant will only be applied when both values are filled.