microsoft-authentication-library-for-js icon indicating copy to clipboard operation
microsoft-authentication-library-for-js copied to clipboard

Allow extending MsalGuard

Open svrooij opened this issue 4 years ago • 2 comments

Core Library

@azure/msal-browser

Wrapper Library

@azure/msal-angular

Description

The MsalGuard works great for basic usecases, but sometimes you just need a small change. At the moment you'll need to copy all the code from the MsalGuard into a new Guard. It would be great if the activateHelper would be marked as protected. (And also marking all the properties in the constructor as protected)

That would allow to create an extended MsalGuard really easily:

import { RouterStateSnapshot, UrlTree } from "@angular/router";
import { Observable } from "rxjs";
import { MsalGuard } from "./msal.guard";

export class RoleMsalGuard extends MsalGuard {
  activateHelper(state?: RouterStateSnapshot): Observable<boolean|UrlTree> {
    let result = super.activateHelper(state);

    // Do something here with the result

    return result;
  }
}

Source

External (Customer)

svrooij avatar Apr 07 '21 08:04 svrooij

@svrooij Thanks for filing, we'll take this into consideration.

jasonnutter avatar Apr 07 '21 15:04 jasonnutter

Class and InjectionToken guards and resolvers, such as the current MsalGuard implementation, are scheduled for removal in Angular 17. I would not recommend extending (or allowing users to extend) MsalGuard as it will introduce additional complications when it is removed in order to support newer Angular versions.

dirthsj avatar Mar 17 '23 21:03 dirthsj