Merged in development (pull request #14)

Development
This commit is contained in:
Leandro Costa 2023-11-09 17:02:04 +00:00
commit 0f23e423e1
4 changed files with 11 additions and 9 deletions

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "lhisp-oauth-client", "name": "lhisp-oauth-client",
"version": "1.0.21", "version": "1.0.23",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "lhisp-oauth-client", "name": "lhisp-oauth-client",
"version": "1.0.21", "version": "1.0.23",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"axios": "^1.6.1", "axios": "^1.6.1",

View file

@ -1,6 +1,6 @@
{ {
"name": "lhisp-oauth-client", "name": "lhisp-oauth-client",
"version": "1.0.21", "version": "1.0.23",
"main": "src/index", "main": "src/index",
"types": "src/index.d.ts", "types": "src/index.d.ts",
"repository": "git@bitbucket.org:leandro_costa/lhisp-oauth-client.git", "repository": "git@bitbucket.org:leandro_costa/lhisp-oauth-client.git",

View file

@ -18,7 +18,7 @@ export interface LhispOauthClientConstructorParams {
grantType?: string; grantType?: string;
authContentType?: ContentType; authContentType?: ContentType;
sendAuthCredentialsOnRequestBody?: boolean; sendAuthCredentialsOnRequestBody?: boolean;
forceTokenTypeToCamelCase?: boolean; formatAccessToken?: (accessToken?: AccessToken) => string;
debug?: boolean; debug?: boolean;
} }

View file

@ -32,7 +32,7 @@ export class LhispOauthClient<iAccessToken extends AccessToken = AccessToken> {
protected tokenCreatedAt = 0; protected tokenCreatedAt = 0;
protected tokenExpiresIn = 0; protected tokenExpiresIn = 0;
protected sendAuthCredentialsOnRequestBody?: boolean; protected sendAuthCredentialsOnRequestBody?: boolean;
protected forceTokenTypeToCamelCase?: boolean; protected formatAccessToken?: (accessToken?: iAccessToken) => string;
constructor(params: LhispOauthClientConstructorParams) { constructor(params: LhispOauthClientConstructorParams) {
if (params.certificado) { if (params.certificado) {
@ -59,6 +59,7 @@ export class LhispOauthClient<iAccessToken extends AccessToken = AccessToken> {
this.authHeaderName = params.authHeaderName || defaultAuthHeaderName; this.authHeaderName = params.authHeaderName || defaultAuthHeaderName;
this.tokenHeaderName = params.tokenHeaderName || defaultTokenHeaderName; this.tokenHeaderName = params.tokenHeaderName || defaultTokenHeaderName;
this.sendAuthCredentialsOnRequestBody = params.sendAuthCredentialsOnRequestBody; this.sendAuthCredentialsOnRequestBody = params.sendAuthCredentialsOnRequestBody;
this.formatAccessToken = params.formatAccessToken;
} }
getAuthHeaderValue(): string { getAuthHeaderValue(): string {
@ -132,10 +133,11 @@ export class LhispOauthClient<iAccessToken extends AccessToken = AccessToken> {
} }
getAuthToken() { getAuthToken() {
const tokenType = this.forceTokenTypeToCamelCase if (this.formatAccessToken) {
? `${this.accessToken?.token_type?.[0]?.toUpperCase()}${this.accessToken?.token_type?.substring(1)}` return this.formatAccessToken(this.accessToken);
: this.accessToken?.token_type; }
return `${tokenType} ${this.accessToken?.access_token}`;
return `${this.accessToken?.token_type} ${this.accessToken?.access_token}`;
} }
async executarRequest<ResponseType>({ async executarRequest<ResponseType>({