@laserfiche/lf-api-client-core
Advanced tools
Comparing version
@@ -6,3 +6,3 @@ import { HttpRequestHandler } from './HttpRequestHandler.js'; | ||
private _getAccessTokenAsyncFunc; | ||
private _accessToken; | ||
private _accessTokenInfo?; | ||
/** | ||
@@ -9,0 +9,0 @@ * Constructor |
@@ -10,3 +10,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { JwtUtils } from '../../index.js'; | ||
import * as JwtUtils from '../utils/JwtUtils.js'; | ||
export class OAuthClientCustomTokenCredentialsHandler { | ||
@@ -29,17 +29,29 @@ /** | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this._accessToken) { | ||
let resp = yield this._getAccessTokenAsyncFunc(); | ||
if (resp === null || resp === void 0 ? void 0 : resp.access_token) | ||
this._accessToken = resp.access_token; | ||
else | ||
console.warn(`getAccessToken did not return a token. ${resp}`); | ||
if (!this._accessTokenInfo) { | ||
try { | ||
let resp = yield this._getAccessTokenAsyncFunc(); | ||
if (resp === null || resp === void 0 ? void 0 : resp.access_token) { | ||
const jwt = JwtUtils.parseAccessToken(resp.access_token); | ||
const regionalDomain = JwtUtils.getAudFromLfJWT(jwt); | ||
this._accessTokenInfo = { | ||
accessToken: resp.access_token, | ||
regionalDomain, | ||
}; | ||
} | ||
else { | ||
throw Error(`${resp}`); | ||
} | ||
} | ||
catch (err) { | ||
throw Error(`Invalid or missing access token: ${err.message}`); | ||
} | ||
} | ||
if (this._accessToken) { | ||
request.headers['Authorization'] = 'Bearer ' + this._accessToken; | ||
if (this._accessTokenInfo) { | ||
request.headers['Authorization'] = 'Bearer ' + this._accessTokenInfo.accessToken; | ||
return { | ||
regionalDomain: JwtUtils.getAudFromLfJWT(JwtUtils.parseAccessToken(this._accessToken)), | ||
regionalDomain: this._accessTokenInfo.regionalDomain, | ||
}; | ||
} | ||
else { | ||
throw Error("Unexpected, no access token."); | ||
throw Error('Missing access token'); | ||
} | ||
@@ -58,3 +70,3 @@ }); | ||
if (response.status === 401) { | ||
this._accessToken = undefined; | ||
this._accessTokenInfo = undefined; | ||
return true; | ||
@@ -61,0 +73,0 @@ } |
{ | ||
"name": "@laserfiche/lf-api-client-core", | ||
"version": "1.1.14--preview-11390787425", | ||
"version": "1.1.14--preview-11464523894", | ||
"description": "", | ||
@@ -36,2 +36,3 @@ "main": "dist/index.js", | ||
"ts-jest": "^28.0.8", | ||
"tslib": "^2.6.3", | ||
"typescript": "^4.5.4" | ||
@@ -38,0 +39,0 @@ }, |
Sorry, the diff of this file is not supported yet
86182
0.88%1431
0.85%15
7.14%