Skip to content

Commit

Permalink
Support leid (blackbaud#406)
Browse files Browse the repository at this point in the history
* Added support for leid

* Added tests.

* Pointing to auth-client PR branch

* Poing to released auth-client

* Using const
  • Loading branch information
Bobby Earl authored and Blackbaud-MikitaYankouski committed May 3, 2019
1 parent 39abd82 commit a087e58
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@angular/platform-browser": "4.3.6",
"@angular/platform-browser-dynamic": "4.3.6",
"@angular/router": "4.3.6",
"@blackbaud/auth-client": "2.5.0",
"@blackbaud/auth-client": "2.6.0",
"@blackbaud/skyux-lib-help": "1.3.0",
"@blackbaud/skyux-logger": "1.0.2",
"@ngtools/webpack": "1.3.1",
Expand Down
25 changes: 24 additions & 1 deletion runtime/auth-http.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('SkyAuthHttp', () => {
runtime: {
params: new SkyAppRuntimeConfigParams(url, [
'envid',
'leid',
'svcid'
])
}
Expand Down Expand Up @@ -72,7 +73,7 @@ describe('SkyAuthHttp', () => {
});
});

it('should include svc if it is in the current url', (done) => {
it('should include svcid if it is in the current url', (done) => {
const search = '?svcid=1234';
spyOn(BBAuth, 'getToken').and.returnValue(Promise.resolve());

Expand All @@ -83,6 +84,17 @@ describe('SkyAuthHttp', () => {
});
});

it('should include leid if it is in the current url', (done) => {
const search = '?leid=1234';
spyOn(BBAuth, 'getToken').and.returnValue(Promise.resolve());

setupInjector(search);
skyAuthHttp.get('example.com').subscribe(() => {
expect(lastConnection.request.url).toContain(search);
done();
});
});

it('should include envid and svcid if they are in the current url', (done) => {
const search = '?envid=1234&svcid=5678';
spyOn(BBAuth, 'getToken').and.returnValue(Promise.resolve());
Expand All @@ -94,6 +106,17 @@ describe('SkyAuthHttp', () => {
});
});

it('should include envid, svcid, and leid if they are in the current url', (done) => {
const search = '?envid=123&svcid=456&leid=789';
spyOn(BBAuth, 'getToken').and.returnValue(Promise.resolve());

setupInjector(search);
skyAuthHttp.get('example.com').subscribe(() => {
expect(lastConnection.request.url).toContain(search);
done();
});
});

it('should not pass through unknown query params', (done) => {
const search = '?junk=asdf';
spyOn(BBAuth, 'getToken').and.returnValue(Promise.resolve());
Expand Down
17 changes: 12 additions & 5 deletions runtime/auth-http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,18 @@ export class SkyAuthHttp extends Http {
url: string | Request,
options?: RequestOptionsArgs
): Observable<Response> {
let tokenArgs: BBAuthGetTokenArgs;
const tokenArgs: BBAuthGetTokenArgs = {};
const leId: string = this.getLeId();

// See if this call was chained to withScope(), and if so, provide it when
// retrieving a token.
if (this.permissionScope) {
tokenArgs = {
envId: this.getEnvId(),
permissionScope: this.permissionScope
};
tokenArgs.envId = this.getEnvId();
tokenArgs.permissionScope = this.permissionScope;
}

if (leId) {
tokenArgs.leId = leId;
}

return Observable.fromPromise(this.authTokenProvider.getToken(tokenArgs))
Expand Down Expand Up @@ -112,4 +115,8 @@ export class SkyAuthHttp extends Http {
private getEnvId() {
return this.skyAppConfig.runtime.params.get('envid');
}

private getLeId() {
return this.skyAppConfig.runtime.params.get('leid');
}
}
1 change: 1 addition & 0 deletions skyuxconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"params": {
"addin": true,
"envid": true,
"leid": true,
"svcid": true
},
"skyuxModules": [
Expand Down
5 changes: 4 additions & 1 deletion src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ describe('AppComponent', () => {
experimental: true
};

skyAppConfig.skyux.params = ['envid', 'svcid'];
skyAppConfig.skyux.params = ['envid', 'svcid', 'leid'];
skyAppConfig.runtime.params.has = (key: any) => true;
skyAppConfig.runtime.params.get = (key: any) => key + 'Value';
setup(skyAppConfig, true).then(() => {
Expand All @@ -456,6 +456,9 @@ describe('AppComponent', () => {

// Notice svcid => svcId
expect(spyOmnibar.calls.first().args[0].svcId).toEqual('svcidValue');

// Notice svcid => svcId
expect(spyOmnibar.calls.first().args[0].leId).toEqual('leidValue');
});
}));

Expand Down
17 changes: 11 additions & 6 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,17 @@ export class AppComponent implements OnInit, OnDestroy {
// Only pass params that omnibar config cares about
// Internally we store as envid/svcid but auth-client wants envId/svcId
private setParamsFromQS(omnibarConfig: any) {
if (this.config.runtime.params.has('envid')) {
omnibarConfig.envId = this.config.runtime.params.get('envid');
}
if (this.config.runtime.params.has('svcid')) {
omnibarConfig.svcId = this.config.runtime.params.get('svcid');
}
const map: { [key: string]: string } = {
envid: 'envId',
leid: 'leId',
svcid: 'svcId'
};

Object.keys(map).forEach((key: string) => {
if (this.config.runtime.params.has(key)) {
omnibarConfig[map[key]] = this.config.runtime.params.get(key);
}
});
}

private setOnSearch(omnibarConfig: any) {
Expand Down

0 comments on commit a087e58

Please sign in to comment.