commit
b466426f77
5 changed files with 8 additions and 26 deletions
|
@ -105,24 +105,6 @@ describe("Get Access Token", () => {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Shoud Get with Credentials without ContentType", async () => {
|
|
||||||
const cli = getOauthClient({
|
|
||||||
...baseClientParams,
|
|
||||||
disableAuthContentType: true,
|
|
||||||
});
|
|
||||||
await accessTokenValidator(cli);
|
|
||||||
expect(mockedAxios.request).toBeCalledWith(
|
|
||||||
expect.objectContaining({
|
|
||||||
url: authUrl,
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
Authorization: basicAuth,
|
|
||||||
},
|
|
||||||
data: `grant_type=${defaultGrantValue}`,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Request", () => {
|
describe("Request", () => {
|
||||||
|
|
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "lhisp-oauth-client",
|
"name": "lhisp-oauth-client",
|
||||||
"version": "1.0.14",
|
"version": "1.0.15",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "lhisp-oauth-client",
|
"name": "lhisp-oauth-client",
|
||||||
"version": "1.0.14",
|
"version": "1.0.15",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.4.0",
|
"axios": "^1.4.0",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "lhisp-oauth-client",
|
"name": "lhisp-oauth-client",
|
||||||
"version": "1.0.14",
|
"version": "1.0.15",
|
||||||
"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",
|
||||||
|
|
|
@ -18,7 +18,6 @@ export interface LhispOauthClientConstructorParams {
|
||||||
grantType?: string;
|
grantType?: string;
|
||||||
authContentType?: ContentType;
|
authContentType?: ContentType;
|
||||||
sendAuthCredentialsOnRequestBody?: boolean;
|
sendAuthCredentialsOnRequestBody?: boolean;
|
||||||
disableAuthContentType?: boolean;
|
|
||||||
debug?: boolean;
|
debug?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ export class LhispOauthClient<iAccessToken extends AccessToken = AccessToken> {
|
||||||
protected authHeaderName: string;
|
protected authHeaderName: string;
|
||||||
protected tokenHeaderName: string;
|
protected tokenHeaderName: string;
|
||||||
protected authContentType: ContentType;
|
protected authContentType: ContentType;
|
||||||
protected disableAuthContentType = false;
|
|
||||||
protected certificado?: string;
|
protected certificado?: string;
|
||||||
protected senhaCertificado?: string;
|
protected senhaCertificado?: string;
|
||||||
protected authScope?: string;
|
protected authScope?: string;
|
||||||
|
@ -54,7 +53,6 @@ export class LhispOauthClient<iAccessToken extends AccessToken = AccessToken> {
|
||||||
this.authScope = params.authScope;
|
this.authScope = params.authScope;
|
||||||
this.grantType = params.grantType || defaultGrantType;
|
this.grantType = params.grantType || defaultGrantType;
|
||||||
this.authContentType = params.authContentType || defaultAuthContentType;
|
this.authContentType = params.authContentType || defaultAuthContentType;
|
||||||
this.disableAuthContentType = Boolean(params.disableAuthContentType);
|
|
||||||
this.clientId = params.clientId;
|
this.clientId = params.clientId;
|
||||||
this.clientSecret = params.clientSecret;
|
this.clientSecret = params.clientSecret;
|
||||||
this.authHeaderName = params.authHeaderName || defaultAuthHeaderName;
|
this.authHeaderName = params.authHeaderName || defaultAuthHeaderName;
|
||||||
|
@ -100,7 +98,7 @@ export class LhispOauthClient<iAccessToken extends AccessToken = AccessToken> {
|
||||||
httpsAgent: this.agent,
|
httpsAgent: this.agent,
|
||||||
headers: {
|
headers: {
|
||||||
[this.authHeaderName]: this.getAuthHeaderValue(),
|
[this.authHeaderName]: this.getAuthHeaderValue(),
|
||||||
...(this.disableAuthContentType ? {} : { "Content-Type": this.authContentType }),
|
"Content-Type": this.authContentType,
|
||||||
},
|
},
|
||||||
data: {},
|
data: {},
|
||||||
};
|
};
|
||||||
|
@ -113,7 +111,10 @@ export class LhispOauthClient<iAccessToken extends AccessToken = AccessToken> {
|
||||||
if (this.clientSecret) authRequestOpt.data.client_secret = this.clientSecret;
|
if (this.clientSecret) authRequestOpt.data.client_secret = this.clientSecret;
|
||||||
}
|
}
|
||||||
|
|
||||||
authRequestOpt.data = this.parseData({ data: authRequestOpt.data, contentType: this.authContentType });
|
authRequestOpt.data = this.parseData({
|
||||||
|
data: authRequestOpt.data,
|
||||||
|
contentType: this.authContentType,
|
||||||
|
});
|
||||||
const resp = await axios.request(authRequestOpt);
|
const resp = await axios.request(authRequestOpt);
|
||||||
this.accessToken = this.buildAccessToken(resp.data);
|
this.accessToken = this.buildAccessToken(resp.data);
|
||||||
this.tokenCreatedAt = new Date().getTime();
|
this.tokenCreatedAt = new Date().getTime();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue