commit
500cd95309
4 changed files with 829 additions and 550 deletions
1345
package-lock.json
generated
1345
package-lock.json
generated
File diff suppressed because it is too large
Load diff
16
package.json
16
package.json
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "lhisp-oauth-client",
|
||||
"version": "1.0.17",
|
||||
"version": "1.0.21",
|
||||
"main": "src/index",
|
||||
"types": "src/index.d.ts",
|
||||
"repository": "git@bitbucket.org:leandro_costa/lhisp-oauth-client.git",
|
||||
|
@ -12,14 +12,14 @@
|
|||
"test:watch": "jest --watchAll"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.5.2",
|
||||
"@types/node": "^20.3.1",
|
||||
"jest": "^29.5.0",
|
||||
"ts-jest": "^29.1.0",
|
||||
"typescript": "^5.1.3"
|
||||
"@types/jest": "^29.5.8",
|
||||
"@types/node": "^20.9.0",
|
||||
"jest": "^29.7.0",
|
||||
"ts-jest": "^29.1.1",
|
||||
"typescript": "^5.2.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.4.0",
|
||||
"lhisp-logger": "^1.0.11"
|
||||
"axios": "^1.6.1",
|
||||
"lhisp-logger": "^1.0.14"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ export interface LhispOauthClientConstructorParams {
|
|||
apiUrl: string;
|
||||
clientId: string;
|
||||
clientSecret: string;
|
||||
certificado?: string;
|
||||
certificado?: string | Buffer;
|
||||
senhaCertificado?: string;
|
||||
authScope?: string;
|
||||
authHeaderName?: string;
|
||||
|
@ -18,6 +18,7 @@ export interface LhispOauthClientConstructorParams {
|
|||
grantType?: string;
|
||||
authContentType?: ContentType;
|
||||
sendAuthCredentialsOnRequestBody?: boolean;
|
||||
forceTokenTypeToCamelCase?: boolean;
|
||||
debug?: boolean;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import qs from "querystring";
|
||||
import https from "https";
|
||||
import axios, { AxiosRequestConfig } from "axios";
|
||||
import axios, { AxiosHeaders, AxiosRequestConfig } from "axios";
|
||||
import {
|
||||
AccessToken,
|
||||
ContentType,
|
||||
|
@ -24,7 +24,7 @@ export class LhispOauthClient<iAccessToken extends AccessToken = AccessToken> {
|
|||
protected certificado?: string | Buffer;
|
||||
protected senhaCertificado?: string;
|
||||
protected authScope?: string;
|
||||
protected headers?: Headers;
|
||||
protected headers?: AxiosHeaders;
|
||||
protected grantType?: string;
|
||||
protected agent: https.Agent;
|
||||
protected accessToken?: iAccessToken;
|
||||
|
@ -32,6 +32,7 @@ export class LhispOauthClient<iAccessToken extends AccessToken = AccessToken> {
|
|||
protected tokenCreatedAt = 0;
|
||||
protected tokenExpiresIn = 0;
|
||||
protected sendAuthCredentialsOnRequestBody?: boolean;
|
||||
protected forceTokenTypeToCamelCase?: boolean;
|
||||
|
||||
constructor(params: LhispOauthClientConstructorParams) {
|
||||
if (params.certificado) {
|
||||
|
@ -47,7 +48,7 @@ export class LhispOauthClient<iAccessToken extends AccessToken = AccessToken> {
|
|||
}
|
||||
|
||||
this.certificado = params.certificado;
|
||||
this.headers = (params.headers ? params.headers : {}) as any as Headers;
|
||||
this.headers = (params.headers ? params.headers : {}) as any as AxiosHeaders;
|
||||
this.apiUrl = params.apiUrl;
|
||||
this.authUrl = params.authUrl;
|
||||
this.authScope = params.authScope;
|
||||
|
@ -131,7 +132,10 @@ export class LhispOauthClient<iAccessToken extends AccessToken = AccessToken> {
|
|||
}
|
||||
|
||||
getAuthToken() {
|
||||
return `${this.accessToken?.token_type} ${this.accessToken?.access_token}`;
|
||||
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}`;
|
||||
}
|
||||
|
||||
async executarRequest<ResponseType>({
|
||||
|
@ -144,9 +148,10 @@ export class LhispOauthClient<iAccessToken extends AccessToken = AccessToken> {
|
|||
try {
|
||||
await this.getAccessToken();
|
||||
|
||||
let headers = {
|
||||
const headers = {
|
||||
"Content-Type": contentType,
|
||||
[this.tokenHeaderName]: this.getAuthToken(),
|
||||
...(this.headers || {}),
|
||||
};
|
||||
|
||||
const response = await axios.request<ResponseType>({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue