Skip to content

Commit 57cbc44

Browse files
updated code as per feedback
1 parent 525affc commit 57cbc44

12 files changed

+1235
-55
lines changed

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -255,5 +255,4 @@ paket-files/
255255
lib/*.js
256256
lib/*.js.map
257257
#tests/unit/*.js # TODO add these once the unit tests are in TS
258-
#tests/unit/*.js.map
259-
out
258+
#tests/unit/*.js.map

lib/AccessTokenCacheItem.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ namespace MSAL {
88
}
99
}
1010
}
11+

lib/AccessTokenKey.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ namespace MSAL {
22
export class AccessTokenKey {
33
authority: string;
44
clientId: string;
5-
homeObjectId: string;
5+
userIdentifier: string;
66
Scopes: string;
77

8-
constructor(authority: string, clientId: string, scopes: string, homeObjectId: string) {
8+
constructor(authority: string, clientId: string, scopes: string, userIdentifier: string) {
99
this.authority = authority;
1010
this.clientId = clientId;
1111
this.Scopes = scopes;
12-
this.homeObjectId = homeObjectId;
12+
this.userIdentifier = userIdentifier;
1313
}
1414
}
1515
}

lib/AuthenticationRequestParameters.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,37 @@ namespace MSAL {
2828
this.responseType = responseType;
2929
this.redirectUri = redirectUri;
3030
// randomly generated values
31-
if (responseType !== "token")
32-
this.nonce = Utils.Guid();
33-
this.correlationId = Utils.Guid();
34-
this.state = Utils.Guid();
35-
this.nonce = Utils.Guid();
31+
if (responseType !== "token") {
32+
this.nonce = Utils.CreateNewGuid();
33+
}
34+
this.correlationId = Utils.CreateNewGuid();
35+
this.state = Utils.CreateNewGuid();
36+
this.nonce = Utils.CreateNewGuid();
3637
// telemetry information
3738
this.xClientSku = "Js";
3839
this.xClientVer = Utils.GetLibraryVersion();
3940
}
4041

4142
CreateNavigateUrl(scopes: Array<string>): string {
42-
if (!scopes)
43+
if (!scopes) {
4344
scopes = [this.clientId];
45+
}
4446
let requestUrl = "";
4547
let str: Array<string> = [];
4648
str.push('?response_type=' + this.responseType);
4749
if (this.responseType === ResponseTypes[ResponseTypes.id_token]) {
48-
if (scopes.indexOf(this.clientId) > -1)
50+
if (scopes.indexOf(this.clientId) > -1) {
4951
this.translateclientIdUsedInScope(scopes);
52+
}
5053
}
51-
5254
str.push('scope=' + encodeURIComponent(this.parseScope(scopes)));
5355
str.push('client_id=' + encodeURIComponent(this.clientId));
5456
str.push('redirect_uri=' + encodeURIComponent(this.redirectUri));
5557
str.push('state=' + encodeURIComponent(this.state));
5658
str.push('nonce=' + encodeURIComponent(this.nonce));
57-
if (this.extraQueryParameters)
59+
if (this.extraQueryParameters) {
5860
str.push(this.extraQueryParameters);
61+
}
5962
str.push('client-request-id=' + encodeURIComponent(this.correlationId));
6063
requestUrl = this.authority + '/oauth2/v2.0/authorize' + str.join('&') + "&x-client-SKU=" + this.xClientSku + "&x-client-Ver=" + this.xClientVer;
6164
return requestUrl;

lib/Logger.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace MSAL {
22

33
export interface ILoggerCallback {
4-
(level: LogLevel, message: string,containsPii:boolean): boolean;
4+
(level: LogLevel, message: string,containsPii:boolean): void;
55
}
66

77
export enum LogLevel {
@@ -15,11 +15,15 @@ namespace MSAL {
1515
private static _instance: Logger;
1616
private _correlationId: string;
1717
get correlationId(): string { return this._correlationId; }
18+
set correlationId(correlationId: string) {
19+
this._correlationId = correlationId;
20+
};
1821
private _level: LogLevel = LogLevel.Info;
1922
get level(): LogLevel { return this._level; }
2023
set level(logLevel: LogLevel) {
21-
if (LogLevel[logLevel])
24+
if (LogLevel[logLevel]) {
2225
this._level = logLevel;
26+
}
2327
else throw new Error("Provide a valid value for level. Possibles range for logLevel is 0-3");
2428
};
2529

@@ -32,6 +36,9 @@ namespace MSAL {
3236
private _localCallback: ILoggerCallback;
3337
get localCallback(): ILoggerCallback { return this._localCallback; }
3438
set localCallback(localCallback: ILoggerCallback) {
39+
if (this.localCallback) {
40+
throw new Error("MSAL logging callback can only be set once per process and should never change once set.");
41+
}
3542
this._localCallback = localCallback;
3643
};
3744

@@ -49,18 +56,19 @@ namespace MSAL {
4956
}
5057
var timestamp = new Date().toUTCString();
5158
var log: string = '';
52-
if (!Utils.isEmpty(this.correlationId))
59+
if (!Utils.isEmpty(this.correlationId)) {
5360
log = timestamp + ':' + this._correlationId + '-' + Utils.GetLibraryVersion() + '-' + LogLevel[logLevel] + ' ' + logMessage;
54-
else
61+
}
62+
else {
5563
log = timestamp + ':' + Utils.GetLibraryVersion() + '-' + LogLevel[logLevel] + ' ' + logMessage;
56-
64+
}
5765
this.executeCallback(logLevel, log, containsPii);
58-
5966
}
6067

6168
executeCallback(level: LogLevel, message: string, containsPii: boolean) {
62-
if (this.localCallback)
69+
if (this.localCallback) {
6370
this.localCallback(level, message, containsPii);
71+
}
6472
}
6573

6674
error(message: string): void {
@@ -94,7 +102,5 @@ namespace MSAL {
94102
verbosePii(message: string): void {
95103
this.LogMessage(message, LogLevel.Verbose, true);
96104
}
97-
98105
}
99-
100106
}

lib/RequestContext.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace MSAL {// Singleton Class
1010
if (RequestContext._instance) {
1111
return RequestContext._instance;
1212
}
13+
1314
this._logger = new Logger(correlationId);
1415
this._correlationId = this._logger.correlationId;
1516
RequestContext._instance = this;

lib/User.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace MSAL {
2+
export interface User {
3+
username: string;
4+
profile: any;
5+
}
6+
}

0 commit comments

Comments
 (0)