diff --git a/package-lock.json b/package-lock.json index cccb2e9..5cffcfc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "lhisp-oauth-client", - "version": "1.0.21", + "version": "1.0.23", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "lhisp-oauth-client", - "version": "1.0.21", + "version": "1.0.23", "license": "MIT", "dependencies": { "axios": "^1.6.1", diff --git a/package.json b/package.json index e16a8e4..37aca59 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lhisp-oauth-client", - "version": "1.0.21", + "version": "1.0.23", "main": "src/index", "types": "src/index.d.ts", "repository": "git@bitbucket.org:leandro_costa/lhisp-oauth-client.git", diff --git a/src/lhisp-oauth-client.t.ts b/src/lhisp-oauth-client.t.ts index 288fbe4..3ad36cc 100644 --- a/src/lhisp-oauth-client.t.ts +++ b/src/lhisp-oauth-client.t.ts @@ -18,7 +18,7 @@ export interface LhispOauthClientConstructorParams { grantType?: string; authContentType?: ContentType; sendAuthCredentialsOnRequestBody?: boolean; - forceTokenTypeToCamelCase?: boolean; + formatAccessToken?: (accessToken?: AccessToken) => string; debug?: boolean; } diff --git a/src/lhisp-oauth-client.ts b/src/lhisp-oauth-client.ts index 5e22a1b..cd0a8ef 100644 --- a/src/lhisp-oauth-client.ts +++ b/src/lhisp-oauth-client.ts @@ -32,7 +32,7 @@ export class LhispOauthClient { protected tokenCreatedAt = 0; protected tokenExpiresIn = 0; protected sendAuthCredentialsOnRequestBody?: boolean; - protected forceTokenTypeToCamelCase?: boolean; + protected formatAccessToken?: (accessToken?: iAccessToken) => string; constructor(params: LhispOauthClientConstructorParams) { if (params.certificado) { @@ -59,6 +59,7 @@ export class LhispOauthClient { this.authHeaderName = params.authHeaderName || defaultAuthHeaderName; this.tokenHeaderName = params.tokenHeaderName || defaultTokenHeaderName; this.sendAuthCredentialsOnRequestBody = params.sendAuthCredentialsOnRequestBody; + this.formatAccessToken = params.formatAccessToken; } getAuthHeaderValue(): string { @@ -132,10 +133,11 @@ export class LhispOauthClient { } getAuthToken() { - const tokenType = this.forceTokenTypeToCamelCase - ? `${this.accessToken?.token_type?.[0]?.toUpperCase()}${this.accessToken?.token_type?.substring(1)}` - : this.accessToken?.token_type; - return `${tokenType} ${this.accessToken?.access_token}`; + if (this.formatAccessToken) { + return this.formatAccessToken(this.accessToken); + } + + return `${this.accessToken?.token_type} ${this.accessToken?.access_token}`; } async executarRequest({