Skip to content

Commit e5cb3ff

Browse files
authored
Merged back fixes from managed version. (#1702)
1 parent e8da2a0 commit e5cb3ff

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

src/authentication/accessToken.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ export class AccessToken {
3737
}
3838

3939
private static parseSharedAccessSignature(value: string): AccessToken {
40-
const regex = /^[\w\-]*\&(\d*)\&/gm;
40+
const regex = /^([\w\-]*)\&(\d*)\&/gm;
4141
const match = regex.exec(value);
4242

43-
if (!match || match.length < 2) {
43+
if (!match || match.length < 3) {
4444
throw new Error(`SharedAccessSignature token format is not valid.`);
4545
}
4646

47-
const dateTime = match[1];
47+
const userId = match[1];
48+
const dateTime = match[2];
4849
const year = dateTime.substr(0, 4);
4950
const month = dateTime.substr(4, 2);
5051
const day = dateTime.substr(6, 2);
@@ -53,7 +54,7 @@ export class AccessToken {
5354
const dateTimeIso = `${year}-${month}-${day}T${hour}:${minute}:00.000Z`;
5455
const expirationDateUtc = new Date(dateTimeIso);
5556

56-
return new AccessToken("SharedAccessSignature", value, expirationDateUtc);
57+
return new AccessToken("SharedAccessSignature", value, expirationDateUtc, userId);
5758
}
5859

5960
private static parseBearerToken(value: string): AccessToken {

src/components/operations/operation-details/ko/runtime/authorization.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export class Authorization {
3737
public readonly products: ko.Observable<Product[]>;
3838
public readonly selectedSubscriptionKey: ko.Observable<string>;
3939
public readonly collapsedAuth: ko.Observable<boolean>;
40-
4140

4241
constructor(
4342
private readonly sessionManager: SessionManager,
@@ -74,7 +73,7 @@ export class Authorization {
7473
public consoleOperation: ko.Observable<ConsoleOperation>;
7574

7675
@Param()
77-
public headers: ko.ObservableArray<ConsoleHeader>;
76+
public headers: ko.ObservableArray<ConsoleHeader>;
7877

7978
@Param()
8079
public codeSample: ko.Observable<string>;
@@ -151,14 +150,14 @@ export class Authorization {
151150
keyHeader.required = true;
152151
keyHeader.value(accessToken);
153152

154-
if(!this.isGraphQL()) {
153+
if (!this.isGraphQL()) {
155154
this.consoleOperation().request.headers.push(keyHeader);
156155
this.updateRequestSummary();
157156
}
158157
else {
159158
this.headers.push(keyHeader);
160159
}
161-
160+
162161
this.authenticated(true);
163162
}
164163

@@ -195,7 +194,7 @@ export class Authorization {
195194
keyHeader.required = true;
196195
keyHeader.value(subscriptionKey);
197196

198-
if(!this.isGraphQL()) {
197+
if (!this.isGraphQL()) {
199198
this.consoleOperation().request.headers.push(keyHeader);
200199
this.updateRequestSummary();
201200
}
@@ -230,7 +229,7 @@ export class Authorization {
230229
* Initiates specified authentication flow.
231230
* @param grantType OAuth grant type, e.g. "implicit" or "authorization_code".
232231
*/
233-
public async authenticateOAuth(grantType: string): Promise<void> {
232+
public async authenticateOAuth(grantType: string): Promise<void> {
234233
const api = this.api();
235234
const authorizationServer = this.authorizationServer();
236235
const scopeOverride = api.authenticationSettings?.oAuth2?.scope;
@@ -240,7 +239,12 @@ export class Authorization {
240239
authorizationServer.scopes = [scopeOverride];
241240
}
242241

243-
const accessToken = await this.oauthService.authenticate(grantType, authorizationServer);
242+
const accessToken = await this.oauthService.authenticate(grantType, authorizationServer, api.name);
243+
244+
if (!accessToken) {
245+
return;
246+
}
247+
244248
await this.setStoredCredentials(serverName, scopeOverride, grantType, accessToken);
245249

246250
this.setAuthorizationHeader(accessToken);
@@ -276,15 +280,15 @@ export class Authorization {
276280
}
277281

278282
public removeHeader(header: ConsoleHeader): void {
279-
if(!this.isGraphQL()) {
283+
if (!this.isGraphQL()) {
280284
this.consoleOperation().request.headers.remove(header);
281285
this.updateRequestSummary();
282286
}
283287
else {
284288
this.headers.remove(header);
285289
}
286290
}
287-
291+
288292
private async setStoredCredentials(serverName: string, scopeOverride: string, grantType: string, accessToken: string): Promise<void> {
289293
const oauthSession = await this.sessionManager.getItem<OAuthSession>(oauthSessionKey) || {};
290294
const recordKey = this.getSessionRecordKey(serverName, scopeOverride);
@@ -324,7 +328,7 @@ export class Authorization {
324328
this.authorizationError("Oops, something went wrong. Try again later.");
325329
}
326330
}
327-
331+
328332
private async loadSubscriptionKeys(): Promise<void> {
329333
const userId = await this.usersService.getCurrentUserId();
330334

@@ -381,8 +385,8 @@ export class Authorization {
381385
} else {
382386
this.setSubscriptionKeyHeader(subscriptionKey);
383387
}
384-
385-
if(!this.isGraphQL()) {
388+
389+
if (!this.isGraphQL()) {
386390
this.updateRequestSummary();
387391
}
388392
}

src/startup.publish.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import { FileSystemBlobStorage } from "./components/filesystemBlobStorage";
1111
import { ApimPublishModule } from "./apim.publish.module";
1212
import { PublishingCacheModule } from "./persistence/publishingCacheModule";
1313
import { ISettingsProvider } from "@paperbits/common/configuration";
14-
import {staticDataEnvironment} from "./../environmentConstants"
14+
import { staticDataEnvironment } from "./../environmentConstants"
1515

1616
/* Reading settings from configuration file */
1717
let settingsProvider: ISettingsProvider;
18+
1819
if (process.env.NODE_ENV === staticDataEnvironment) {
1920
settingsProvider = new StaticSettingsProvider({
2021
"environment": "publishing",

0 commit comments

Comments
 (0)