Skip to content

Commit 910ec7b

Browse files
committed
Moving graph token out of initialization to be called on demand (#2487)
* Moving graph token to be loaded on demand rather than at initialization time * adding first to subscription so unsubscribe happens and cleans up
1 parent a7cabab commit 910ec7b

File tree

5 files changed

+40
-10
lines changed

5 files changed

+40
-10
lines changed

AzureFunctions.AngularClient/src/app/aad-registration/aad-registration.component.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,13 @@ export class AadRegistrationComponent extends FunctionAppContextComponent implem
6464
}
6565

6666
ngOnInit() {
67-
this._portalService.getStartupInfo().first().subscribe(info => {
68-
this.graphToken = info.graphToken;
69-
this.setModel();
70-
});
67+
this._portalService.getAdToken('graph')
68+
.subscribe(tokenData => {
69+
this.graphToken = tokenData.result.token;
70+
},
71+
err => {
72+
this.processError(err, "Error retrieving graph yoken")
73+
});
7174
}
7275

7376
openAuth() {

AzureFunctions.AngularClient/src/app/shared/models/portal-resources.ts

-3
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,6 @@
650650
public static keysDialog_getFunctionUrl: string = "keysDialog_getFunctionUrl";
651651
public static keysDialog_key: string = "keysDialog_key";
652652
public static keysDialog_url: string = "keysDialog_url";
653-
public static keysDialog_domain: string = "keysDialog_domain";
654-
public static keysDialog_warning: string = "keysDialog_warning";
655-
public static keysDialog_noHttps: string = "keysDialog_noHttps";
656653
public static downloadFunctionAppContent: string = "downloadFunctionAppContent";
657654
public static functionKeys_renewConfirmation: string = "functionKeys_renewConfirmation";
658655
public static emptyBrowse: string = "emptyBrowse";

AzureFunctions.AngularClient/src/app/shared/models/portal.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export interface StartupInfo {
2222
acceptLanguage: string;
2323
effectiveLocale: string;
2424
resourceId: string;
25-
graphToken: string;
2625
theme: string;
2726
crmInfo?: CrmInfo;
2827
armEndpoint?: string;
@@ -198,3 +197,9 @@ export enum PartSize {
198197
*/
199198
Custom = 99,
200199
}
200+
201+
202+
export interface TokenResponse {
203+
tokenType: 'graph' | 'azureTfsApi';
204+
token: string
205+
}

AzureFunctions.AngularClient/src/app/shared/services/portal.service.ts

+27
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,33 @@ export class PortalService {
143143
this.postMessage(Verbs.openBladeCollectorInputs, JSON.stringify(payload));
144144
return this.operationStream
145145
.filter(o => o.operationId === operationId)
146+
.first()
147+
.switchMap((o: DataMessage<BladeResult>) => {
148+
if (o.data.status === 'success') {
149+
return Observable.of(o.data);
150+
} else if (o.data.status === 'cancelled') {
151+
return Observable.of(null);
152+
} else {
153+
return Observable.throw(o.data);
154+
}
155+
});
156+
}
157+
158+
getAdToken(tokenType: 'graph' | 'azureTfsApi'){
159+
this.logAction('portal-service', `get-ad-token: ${tokenType}`, null);
160+
const operationId = Guid.newGuid();
161+
162+
const payload = {
163+
operationId: operationId,
164+
data: {
165+
tokenType: tokenType
166+
}
167+
}
168+
169+
this.postMessage('get-ad-token', JSON.stringify(payload));
170+
return this.operationStream
171+
.filter(o=> o.operationId === operationId)
172+
.first()
146173
.switchMap((o: DataMessage<BladeResult>) => {
147174
if (o.data.status === 'success') {
148175
return Observable.of(o.data);

AzureFunctions.AngularClient/src/app/shared/services/user.service.ts

-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export class UserService {
4343

4444
this._startupInfo = {
4545
token: null,
46-
graphToken: null,
4746
subscriptions: null,
4847
sessionId: null,
4948
acceptLanguage: null,
@@ -131,7 +130,6 @@ export class UserService {
131130
.subscribe(r => {
132131
const info = {
133132
token: token,
134-
graphToken: this._startupInfo.graphToken,
135133
subscriptions: r.subs,
136134
sessionId: this._startupInfo.sessionId,
137135
acceptLanguage: this._startupInfo.acceptLanguage,

0 commit comments

Comments
 (0)