oci-common
Advanced tools
Comparing version 2.55.1 to 2.56.0
import { AuthenticationDetailsProvider, RegionProvider } from "./auth"; | ||
import { ConfigFileAuthenticationDetailsProvider } from "./config-file-auth"; | ||
export declare class SessionAuthDetailProvider extends ConfigFileAuthenticationDetailsProvider implements AuthenticationDetailsProvider, RegionProvider { | ||
private skipRefresh; | ||
constructor(configurationFilePath?: string, profile?: string); | ||
getKeyId(): Promise<string>; | ||
getSecurityToken(): Promise<string>; | ||
private isValidSessionToken; | ||
refreshSessionToken(): Promise<string>; | ||
} |
@@ -11,5 +11,2 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -21,8 +18,7 @@ exports.SessionAuthDetailProvider = void 0; | ||
const config_file_auth_1 = require("./config-file-auth"); | ||
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken")); | ||
const helper_1 = require("../helper"); | ||
const region_1 = require("../region"); | ||
class SessionAuthDetailProvider extends config_file_auth_1.ConfigFileAuthenticationDetailsProvider { | ||
constructor(configurationFilePath, profile) { | ||
super(configurationFilePath, profile); | ||
this.skipRefresh = false; | ||
} | ||
@@ -36,34 +32,15 @@ getKeyId() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.isValidSessionToken() || this.skipRefresh) { | ||
return this.sessionToken; | ||
} | ||
return yield this.refreshSessionToken(); | ||
return this.sessionToken; | ||
}); | ||
} | ||
isValidSessionToken() { | ||
let jwt = null; | ||
try { | ||
const secondsSinceEpoch = Math.round(Date.now() / 1000); | ||
jwt = jsonwebtoken_1.default.decode(this.sessionToken, { complete: true }); | ||
if (jwt == null) { | ||
return false; | ||
} | ||
else if (jwt.payload && jwt.payload.exp > secondsSinceEpoch) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
catch (e) { | ||
throw Error(`Failed to decode token, error: ${e}`); | ||
} | ||
} | ||
refreshSessionToken() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.skipRefresh = true; // avoid infinite loop on calling refreshSessionToken() | ||
try { | ||
const signer = new signer_1.DefaultRequestSigner(this); | ||
const client = new http_1.FetchHttpClient(signer); | ||
const region = this.getRegion().regionId; | ||
const regionId = this.getRegion().regionId; | ||
const region = region_1.Region.fromRegionId(regionId); | ||
const secondLevelDomain = region.realm.secondLevelDomain; | ||
const request = yield request_generator_1.composeRequest({ | ||
baseEndpoint: `https://auth.${region}.oraclecloud.com`, | ||
baseEndpoint: `https://auth.${regionId}.${secondLevelDomain}`, | ||
path: `/v1/authentication/refresh`, | ||
@@ -75,3 +52,2 @@ method: "POST", | ||
const response = yield client.send(request); | ||
this.skipRefresh = false; | ||
if (response.status === 200) { | ||
@@ -93,3 +69,2 @@ const tokenJson = yield response.json(); | ||
catch (e) { | ||
this.skipRefresh = false; | ||
throw new Error(`Failed to refresh the session token due to ${e}`); | ||
@@ -96,0 +71,0 @@ } |
{ | ||
"name": "oci-common", | ||
"version": "2.55.1", | ||
"version": "2.56.0", | ||
"description": "OCI Common module for NodeJS", | ||
@@ -5,0 +5,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
447634
6117