oci-common 2.55.0 → 2.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { AuthenticationDetailsProvider, RegionProvider } from "./auth";
|
|
2
2
|
import { ConfigFileAuthenticationDetailsProvider } from "./config-file-auth";
|
|
3
3
|
export declare class SessionAuthDetailProvider extends ConfigFileAuthenticationDetailsProvider implements AuthenticationDetailsProvider, RegionProvider {
|
|
4
|
-
private skipRefresh;
|
|
5
4
|
constructor(configurationFilePath?: string, profile?: string);
|
|
6
5
|
getKeyId(): Promise<string>;
|
|
7
6
|
getSecurityToken(): Promise<string>;
|
|
8
|
-
private isValidSessionToken;
|
|
9
7
|
refreshSessionToken(): Promise<string>;
|
|
10
8
|
}
|
|
@@ -8,21 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.SessionAuthDetailProvider = void 0;
|
|
16
13
|
const signer_1 = require("../signer");
|
|
17
14
|
const http_1 = require("../http");
|
|
18
15
|
const request_generator_1 = require("../request-generator");
|
|
19
16
|
const config_file_auth_1 = require("./config-file-auth");
|
|
20
|
-
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
21
17
|
const helper_1 = require("../helper");
|
|
18
|
+
const region_1 = require("../region");
|
|
22
19
|
class SessionAuthDetailProvider extends config_file_auth_1.ConfigFileAuthenticationDetailsProvider {
|
|
23
20
|
constructor(configurationFilePath, profile) {
|
|
24
21
|
super(configurationFilePath, profile);
|
|
25
|
-
this.skipRefresh = false;
|
|
26
22
|
}
|
|
27
23
|
getKeyId() {
|
|
28
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -31,45 +27,25 @@ class SessionAuthDetailProvider extends config_file_auth_1.ConfigFileAuthenticat
|
|
|
31
27
|
}
|
|
32
28
|
getSecurityToken() {
|
|
33
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
|
|
35
|
-
return this.sessionToken;
|
|
36
|
-
}
|
|
37
|
-
return yield this.refreshSessionToken();
|
|
30
|
+
return this.sessionToken;
|
|
38
31
|
});
|
|
39
32
|
}
|
|
40
|
-
isValidSessionToken() {
|
|
41
|
-
let jwt = null;
|
|
42
|
-
try {
|
|
43
|
-
const secondsSinceEpoch = Math.round(Date.now() / 1000);
|
|
44
|
-
jwt = jsonwebtoken_1.default.decode(this.sessionToken, { complete: true });
|
|
45
|
-
if (jwt == null) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
else if (jwt.payload && jwt.payload.exp > secondsSinceEpoch) {
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
catch (e) {
|
|
54
|
-
throw Error(`Failed to decode token, error: ${e}`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
33
|
refreshSessionToken() {
|
|
58
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
this.skipRefresh = true; // avoid infinite loop on calling refreshSessionToken()
|
|
60
35
|
try {
|
|
61
36
|
const signer = new signer_1.DefaultRequestSigner(this);
|
|
62
37
|
const client = new http_1.FetchHttpClient(signer);
|
|
63
|
-
const
|
|
38
|
+
const regionId = this.getRegion().regionId;
|
|
39
|
+
const region = region_1.Region.fromRegionId(regionId);
|
|
40
|
+
const secondLevelDomain = region.realm.secondLevelDomain;
|
|
64
41
|
const request = yield request_generator_1.composeRequest({
|
|
65
|
-
baseEndpoint: `https://auth.${
|
|
42
|
+
baseEndpoint: `https://auth.${regionId}.${secondLevelDomain}`,
|
|
66
43
|
path: `/v1/authentication/refresh`,
|
|
67
44
|
method: "POST",
|
|
68
45
|
defaultHeaders: { "content-type": "application/json" },
|
|
69
46
|
bodyContent: JSON.stringify({ currentToken: this.sessionToken })
|
|
70
47
|
});
|
|
71
48
|
const response = yield client.send(request);
|
|
72
|
-
this.skipRefresh = false;
|
|
73
49
|
if (response.status === 200) {
|
|
74
50
|
const tokenJson = yield response.json();
|
|
75
51
|
const tokenStr = tokenJson.token;
|
|
@@ -86,7 +62,6 @@ class SessionAuthDetailProvider extends config_file_auth_1.ConfigFileAuthenticat
|
|
|
86
62
|
}
|
|
87
63
|
}
|
|
88
64
|
catch (e) {
|
|
89
|
-
this.skipRefresh = false;
|
|
90
65
|
throw new Error(`Failed to refresh the session token due to ${e}`);
|
|
91
66
|
}
|
|
92
67
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-auth-details-provider.js","sourceRoot":"","sources":["../../../../../lib/auth/session-auth-details-provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"session-auth-details-provider.js","sourceRoot":"","sources":["../../../../../lib/auth/session-auth-details-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,sCAAiD;AACjD,kCAA0C;AAC1C,4DAAsD;AACtD,yDAA6E;AAC7E,sCAA4C;AAC5C,sCAAmC;AAEnC,MAAa,yBAA0B,SAAQ,0DAAuC;IAEpF,YAAY,qBAA8B,EAAE,OAAgB;QAC1D,KAAK,CAAC,qBAAqB,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IAEY,QAAQ;;YACnB,OAAO,KAAK,GAAG,CAAC,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC;QACjD,CAAC;KAAA;IAEK,gBAAgB;;YACpB,OAAO,IAAI,CAAC,YAAa,CAAC;QAC5B,CAAC;KAAA;IAEY,mBAAmB;;YAC9B,IAAI;gBACF,MAAM,MAAM,GAAG,IAAI,6BAAoB,CAAC,IAAI,CAAC,CAAC;gBAC9C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