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 fc13f49..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,7 +59,7 @@ export class LhispOauthClient { this.authHeaderName = params.authHeaderName || defaultAuthHeaderName; this.tokenHeaderName = params.tokenHeaderName || defaultTokenHeaderName; this.sendAuthCredentialsOnRequestBody = params.sendAuthCredentialsOnRequestBody; - this.forceTokenTypeToCamelCase = params.forceTokenTypeToCamelCase; + this.formatAccessToken = params.formatAccessToken; } getAuthHeaderValue(): string { @@ -133,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({