Skip to content

Commit

Permalink
Merge pull request #2829 from AzureAD/angular-omit-scopes
Browse files Browse the repository at this point in the history
[msal-angular] Make scopes optional for msal-guard config
  • Loading branch information
jo-arroyo committed Jan 7, 2021
2 parents c035396 + cf03114 commit fe9bd40
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Make scopes optional for msal-guard config (#2829)",
"packageName": "@azure/msal-angular",
"email": "joarroyo@microsoft.com",
"dependentChangeType": "patch"
}
2 changes: 1 addition & 1 deletion lib/msal-angular/src/msal.guard.config.ts
Expand Up @@ -7,5 +7,5 @@ import { PopupRequest, RedirectRequest,InteractionType } from "@azure/msal-brows

export type MsalGuardConfiguration = {
interactionType: InteractionType.Popup | InteractionType.Redirect;
authRequest?: PopupRequest | Omit<RedirectRequest, "redirectStartPage">;
authRequest?: Partial<PopupRequest> | Partial<Omit<RedirectRequest, "redirectStartPage">>;
};
6 changes: 3 additions & 3 deletions lib/msal-angular/src/msal.guard.ts
Expand Up @@ -7,7 +7,7 @@ import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateCh
import { MsalService } from "./msal.service";
import { Injectable, Inject } from "@angular/core";
import { Location } from "@angular/common";
import { InteractionType, BrowserConfigurationAuthError, BrowserUtils, UrlString } from "@azure/msal-browser";
import { InteractionType, BrowserConfigurationAuthError, BrowserUtils, UrlString, PopupRequest, RedirectRequest } from "@azure/msal-browser";
import { MsalGuardConfiguration } from "./msal.guard.config";
import { MSAL_GUARD_CONFIG } from "./constants";
import { concatMap, catchError, map } from "rxjs/operators";
Expand Down Expand Up @@ -51,7 +51,7 @@ export class MsalGuard implements CanActivate, CanActivateChild, CanLoad {
private loginInteractively(url: string): Observable<boolean> {
if (this.msalGuardConfig.interactionType === InteractionType.Popup) {
this.authService.getLogger().verbose("Guard - logging in by popup");
return this.authService.loginPopup({ ...this.msalGuardConfig.authRequest })
return this.authService.loginPopup({ ...this.msalGuardConfig.authRequest } as PopupRequest)
.pipe(
map(() => {
this.authService.getLogger().verbose("Guard - login by popup successful, can activate");
Expand All @@ -66,7 +66,7 @@ export class MsalGuard implements CanActivate, CanActivateChild, CanLoad {
this.authService.loginRedirect({
redirectStartPage,
...this.msalGuardConfig.authRequest
});
} as RedirectRequest);
return of(false);
}

Expand Down
@@ -1,6 +1,6 @@
import { Component, OnInit, Inject, OnDestroy, Injectable } from '@angular/core';
import { MsalService, MsalBroadcastService, MSAL_GUARD_CONFIG, MsalGuardConfiguration } from '@azure/msal-angular';
import { EventMessage, EventType, InteractionType } from '@azure/msal-browser';
import { EventMessage, EventType, InteractionType, PopupRequest, RedirectRequest } from '@azure/msal-browser';
import { Subject } from 'rxjs';
import { filter, takeUntil } from 'rxjs/operators';

Expand Down Expand Up @@ -42,10 +42,10 @@ export class AppComponent implements OnInit, OnDestroy {

login() {
if (this.msalGuardConfig.interactionType === InteractionType.Popup) {
this.authService.loginPopup({...this.msalGuardConfig.authRequest})
this.authService.loginPopup({...this.msalGuardConfig.authRequest} as PopupRequest)
.subscribe(() => this.checkAccount());
} else {
this.authService.loginRedirect({...this.msalGuardConfig.authRequest});
this.authService.loginRedirect({...this.msalGuardConfig.authRequest} as RedirectRequest);
}
}

Expand Down
@@ -1,6 +1,6 @@
import { Component, OnInit, Inject, OnDestroy, Injectable } from '@angular/core';
import { MsalService, MsalBroadcastService, MSAL_GUARD_CONFIG, MsalGuardConfiguration } from '@azure/msal-angular';
import { EventMessage, EventType, InteractionType } from '@azure/msal-browser';
import { EventMessage, EventType, InteractionType, PopupRequest, RedirectRequest } from '@azure/msal-browser';
import { Subject } from 'rxjs';
import { filter, takeUntil } from 'rxjs/operators';

Expand Down Expand Up @@ -43,15 +43,15 @@ export class AppComponent implements OnInit, OnDestroy {
login() {
if (this.msalGuardConfig.interactionType === InteractionType.Popup) {
if (this.msalGuardConfig.authRequest){
this.authService.loginPopup({...this.msalGuardConfig.authRequest})
this.authService.loginPopup({...this.msalGuardConfig.authRequest} as PopupRequest)
.subscribe(() => this.checkAccount());
} else {
this.authService.loginPopup()
.subscribe(() => this.checkAccount());
}
} else {
if (this.msalGuardConfig.authRequest){
this.authService.loginRedirect({...this.msalGuardConfig.authRequest});
this.authService.loginRedirect({...this.msalGuardConfig.authRequest} as RedirectRequest);
} else {
this.authService.loginRedirect();
}
Expand Down
@@ -1,6 +1,6 @@
import { Component, OnInit, Inject, OnDestroy, Injectable } from '@angular/core';
import { MsalService, MsalBroadcastService, MSAL_GUARD_CONFIG, MsalGuardConfiguration } from '@azure/msal-angular';
import { EventMessage, EventType, InteractionType } from '@azure/msal-browser';
import { EventMessage, EventType, InteractionType, PopupRequest, RedirectRequest } from '@azure/msal-browser';
import { Subject } from 'rxjs';
import { filter, takeUntil } from 'rxjs/operators';

Expand Down Expand Up @@ -42,10 +42,10 @@ export class AppComponent implements OnInit, OnDestroy {

login() {
if (this.msalGuardConfig.interactionType === InteractionType.Popup) {
this.authService.loginPopup({...this.msalGuardConfig.authRequest})
this.authService.loginPopup({...this.msalGuardConfig.authRequest} as PopupRequest)
.subscribe(() => this.checkAccount());
} else {
this.authService.loginRedirect({...this.msalGuardConfig.authRequest});
this.authService.loginRedirect({...this.msalGuardConfig.authRequest} as RedirectRequest);
}
}

Expand Down

0 comments on commit fe9bd40

Please sign in to comment.