Skip to content

Commit

Permalink
Merge branch 'dev' into merge-config
Browse files Browse the repository at this point in the history
  • Loading branch information
pkanher617 committed May 5, 2020
2 parents f609cd6 + 693e7bc commit be8b3ef
Show file tree
Hide file tree
Showing 21 changed files with 315 additions and 176 deletions.
18 changes: 14 additions & 4 deletions lib/msal-angular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,19 @@ this.broadcastService.subscribe("msal:acquireTokenFailure", payload => {
});
```

3. It is extremely important to unsubscribe. Implement `ngOnDestroy()` in your component and unsubscribe.
3. SSO-related events (`ssoSilent()`)

```js
this.broadcastService.subscribe("msal:ssoSuccess", payload => {
// do something here
});

this.broadcastService.subscribe("msal:ssoFailure", payload => {
// do something here
});
```

4. It is extremely important to unsubscribe. Implement `ngOnDestroy()` in your component and unsubscribe.

```js
private subscription: Subscription;
Expand Down Expand Up @@ -156,9 +168,7 @@ The wrapper exposes APIs for login, logout, acquiring access token and more.
5. `acquireTokenPopup()`
6. `acquireTokenRedirect()`
7. `getAccount()`

> Note: Since MSAL Angular wrapper is inheriting from UserAgentApplication of msal-core, all the public APIs of msal-core are still accessible from msal-angular. But it is recommended not to use
> any of the msal-core APIs like acquireTokenSilent(), acquireTokenPopup(), acquireTokenRedirect() etc from Angular application and use only the APIs which are exposed directly from the msal-angular wrapper itself.
8. `ssoSilent()`

## Advanced Topics

Expand Down
20 changes: 20 additions & 0 deletions lib/msal-angular/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Changelog

## 1.0.0

Stable release of MSAL Angular v1. See beta versions below for complete list of changes.

Highlights:

* Requires `msal@1.3.0`.
* Requires `rxjs@6`.
* Adds support for Angular 6, 7, 8, 9.
* Drops support for Angular 4, 5.
* `MsalModule.forRoot` now takes two arguement.
* The first argument is the configuration object, which is the [same `Configuration` object](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-core/src/Configuration.ts) you would pass to `msal`.
* The second argument is a `MsalAngularConfiguration` object, containing the values for `consentScopes`, `popUp`, and `extraQueryParameters`.
* See the [updated sample](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/samples/angular6-sample-app/src/app/app.module.ts) for an example of how to pass these configuration objects.
* The `acquireToken` and `login` methods now take a single `AuthenticationParameters` object as parameters.
* `getUser()` is now `getAccount()`.
* Broadcast events now emit objects, instead of just strings.
* Applications using `Redirect` methods can optionally implement the `handleRedirectCallback` method (and have it run on every page load), which will capture the result of redirect operations. See the [Angular sample](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/samples/angular6-sample-app/src/app/app.component.ts) for an example of how to implement.
* Add `ssoSilent` API. This API requires either a `loginHint` or `sid`, and is intended to be used when you want to SSO to an existing AAD session. Emits `msal:ssoSuccess` and `msal:ssoFailure` events.

## 1.0.0-beta.5

* Requires `msal@1.3.0-beta.0`.
Expand Down
8 changes: 4 additions & 4 deletions lib/msal-angular/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions lib/msal-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "git",
"url": "https://github.com/AzureAD/microsoft-authentication-library-for-js.git"
},
"version": "1.0.0-beta.5",
"version": "1.0.0",
"keywords": [
"implicit",
"angular",
Expand All @@ -31,7 +31,7 @@
"peerDependencies": {
"@angular/common": ">= 6.0.0",
"@angular/core": ">= 6.0.0",
"msal": "^1.3.0-beta.0",
"msal": "^1.3.0",
"rxjs": "^6.0.0"
},
"devDependencies": {
Expand Down Expand Up @@ -74,7 +74,7 @@
"karma-spec-reporter": "0.0.32",
"karma-verbose-reporter": "0.0.6",
"karma-webpack": "^3.0.0",
"msal": "^1.3.0-beta.0",
"msal": "^1.3.0",
"ng-packagr": "^9.0.2",
"phantomjs-polyfill": "0.0.2",
"reflect-metadata": "^0.1.3",
Expand Down Expand Up @@ -102,6 +102,7 @@
"build": "npm run clean && npm run build:modules",
"deploy": "npm run build && npm publish dist && npm run doc",
"test": "karma start karma.conf.js",
"lint": "tslint -p ./",
"test:verify-build": "npm run build:modules && npm test",
"endToEnd": "cd tests/endToEndTests && npm install && node testRunner.js",
"prepack": "npm run build"
Expand Down
15 changes: 7 additions & 8 deletions lib/msal-angular/src/MSALError.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
export class MSALError {
private _error: string="";
private _errorDesc: string="";
private _scopes: string="";
private _error: string = "";
private _errorDesc: string = "";
private _scopes: string = "";


constructor(error: string , errorDesc?: string, scopes?:string)
{
constructor(error: string , errorDesc?: string, scopes?: string) {
this._error = error;
if(errorDesc) {
if (errorDesc) {
this._errorDesc = errorDesc;
}
if(scopes) {
if (scopes) {
this._scopes = scopes;
}
}
Expand Down Expand Up @@ -38,4 +37,4 @@ export class MSALError {
set scopes(value: string) {
this._scopes = value;
}
}
}
17 changes: 7 additions & 10 deletions lib/msal-angular/src/broadcast.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable, Subscription } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import { Injectable } from "@angular/core";
import { BehaviorSubject, Observable, Subscription } from "rxjs";
import { filter, map } from "rxjs/operators";

export type MessageCallback = (payload: any) => void;

Expand All @@ -9,23 +9,20 @@ export class BroadcastService {
private _msalSubject : BehaviorSubject<any> ;
private msalItem$: Observable<any>;

constructor()
{
constructor() {
this._msalSubject = new BehaviorSubject<any>(1);
this.msalItem$ = this._msalSubject.asObservable();
}

broadcast(type: string ,payload: any) {
broadcast(type: string, payload: any) {
this._msalSubject.next({type , payload});
}

getMSALSubject()
{
getMSALSubject() {
return this._msalSubject;
}

getMSALItem()
{
getMSALItem() {
return this.msalItem$;
}

Expand Down
16 changes: 8 additions & 8 deletions lib/msal-angular/src/msal.interceptor.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { Injectable } from '@angular/core';
import { Injectable } from "@angular/core";
import {
HttpRequest,
HttpHandler,
HttpEvent,
HttpInterceptor,
HttpErrorResponse
} from '@angular/common/http';
} from "@angular/common/http";

import { Observable, from } from 'rxjs';
import { mergeMap, tap } from 'rxjs/operators';
import { Observable, from } from "rxjs";
import { mergeMap, tap } from "rxjs/operators";

import {MsalService} from "./msal.service";
import { BroadcastService } from "./broadcast.service";
import { AuthResponse, ServerHashParamKeys } from 'msal';
import { AuthResponse, ServerHashParamKeys } from "msal";

@Injectable()
export class MsalInterceptor implements HttpInterceptor {
constructor(private auth: MsalService , private broadcastService: BroadcastService) {}

intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const scopes = this.auth.getScopesForEndpoint(req.url);
this.auth.getLogger().verbose('Url: ' + req.url + ' maps to scopes: ' + scopes);
this.auth.getLogger().verbose("Url: " + req.url + " maps to scopes: " + scopes);

// If there are no scopes set for this request, do nothing.
if (!scopes) {
Expand All @@ -45,11 +45,11 @@ export class MsalInterceptor implements HttpInterceptor {
.pipe(
mergeMap(nextReq => next.handle(nextReq)),
tap(
event => {},
event => {}, // tslint:disable-line
err => {
if (err instanceof HttpErrorResponse && err.status === 401) {
this.auth.clearCacheForScope(token);
this.broadcastService.broadcast('msal:notAuthorized', err.message);
this.broadcastService.broadcast("msal:notAuthorized", err.message);
}
}
)
Expand Down
2 changes: 1 addition & 1 deletion lib/msal-angular/src/msal.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class MsalModule {
},
MsalService
]
}
};
}

}
Expand Down
33 changes: 23 additions & 10 deletions lib/msal-angular/src/msal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ export class MsalService extends UserAgentApplication {
this.getLogger().verbose("popUpHashChanged ");
});

window.addEventListener('msal:popUpClosed', (e: CustomEvent) => {
var errorParts = e.detail.split('|');
window.addEventListener("msal:popUpClosed", (e: CustomEvent) => {
var errorParts = e.detail.split("|");
var msalError = new MSALError(errorParts[0], errorParts[1]);
if (this.getLoginInProgress()) {
broadcastService.broadcast('msal:loginFailure', msalError);
broadcastService.broadcast("msal:loginFailure", msalError);
this.setloginInProgress(false);
}
else if (this.getAcquireTokenInProgress()) {
broadcastService.broadcast('msal:acquireTokenFailure', msalError);
broadcastService.broadcast("msal:acquireTokenFailure", msalError);
this.setAcquireTokenInProgress(false);
}
});
Expand Down Expand Up @@ -93,15 +93,28 @@ export class MsalService extends UserAgentApplication {
});
}

public ssoSilent(request: AuthenticationParameters): Promise<AuthResponse> {
return super.ssoSilent(request)
.then((authResponse: AuthResponse) => {
this.broadcastService.broadcast("msal:ssoSuccess", authResponse);
return authResponse;
})
.catch((error: AuthError) => {
this.broadcastService.broadcast("msal:ssoFailure", error);
this.getLogger().error("Error during login:\n" + error.errorMessage);
throw error;
});
}

public acquireTokenSilent(request: AuthenticationParameters): Promise<AuthResponse> {
return super.acquireTokenSilent(request)
.then((authResponse: AuthResponse) => {
this.broadcastService.broadcast('msal:acquireTokenSuccess', authResponse);
this.broadcastService.broadcast("msal:acquireTokenSuccess", authResponse);
return authResponse;
})
.catch((error: AuthError) => {
this.broadcastService.broadcast('msal:acquireTokenFailure', error);
this.getLogger().error('Error when acquiring token for scopes: ' + request.scopes + " " + error);
this.broadcastService.broadcast("msal:acquireTokenFailure", error);
this.getLogger().error("Error when acquiring token for scopes: " + request.scopes + " " + error);
throw error;
});

Expand All @@ -110,12 +123,12 @@ export class MsalService extends UserAgentApplication {
public acquireTokenPopup(request: AuthenticationParameters): Promise<AuthResponse> {
return super.acquireTokenPopup(request)
.then((authResponse: AuthResponse) => {
this.broadcastService.broadcast('msal:acquireTokenSuccess', authResponse);
this.broadcastService.broadcast("msal:acquireTokenSuccess", authResponse);
return authResponse;
})
.catch((error: AuthError) => {
this.broadcastService.broadcast('msal:acquireTokenFailure', error);
this.getLogger().error('Error when acquiring token for scopes : ' + request.scopes +" "+ error);
this.broadcastService.broadcast("msal:acquireTokenFailure", error);
this.getLogger().error("Error when acquiring token for scopes : " + request.scopes + " " + error);
throw error;
});
}
Expand Down

0 comments on commit be8b3ef

Please sign in to comment.