Describe the bug
Ao definir uma classe derivada da interface AuthBasic
e injetá-la no ClientBasic
a autenticação não é realizada corretamente, isso porque o authProvider
está sendo passado diretamente na opção de Proxy do Axios, fazendo com que o pacote não execute corretamente qualquer tipo de autenticação (com exceção da Basic Auth
sem estar encapsulada por um authProvider
).
Your minimal, reproducible example
No response
Steps to reproduce
- Importe o
ClientBasic
.
- Crie um client qualquer que necessite qualquer tipo de autenticação e extenda o
ClientBasic
.
- No construtor do novo cliente, na propriedade
authProvider
injete qualquer tipo de AuthBasic
.
- Instancie o cliente e execute qualquer método que requeira autenticação.
Expected behavior
Como desenvolvedor esperava poder definir diferentes estratégias para autenticação de acordo com a API que esteja integrando, porém a única estratégia de autenticação disponível é via Basic Auth
, utiilizando ainda as opções de Proxy do Axios e não do Provider interno do pacote.
How often does this bug happen?
Every time
Screenshots or Videos
Cliente de Tickets utilizando autenticação base a partir do provedor interno do pacote BasicAuth
.
import { BasicAuth, ClientBasic } from '@coaktion/client-core';
export class TicketsClient extends ClientBasic {
constructor(baseUrl: string) {
super(baseUrl, {
appName: 'tickets-client',
endpoints: {
search: '/tickets',
},
authProvider: new BasicAuth({
username: '[email protected]',
password: 'Aktie@2021!'
})
});
}
}
Cliente de Tickets utilizando autenticação base a partir do Proxy do Axios.
import { ClientBasic } from '@coaktion/client-core';
export class TicketsClient extends ClientBasic {
constructor(baseUrl: string) {
super(baseUrl, {
appName: 'tickets-client',
endpoints: {
search: '/tickets'
},
authProvider: {
username: '[email protected]',
password: 'Aktie@2021!'
}
});
}
}
Platform
- OS: Windows Sub-System for Linux (Ubuntu 20.04)
- Node: 18.12.0
- TypeScript: 4.9.4
Package version
v1.1.2
Additional context
Atualmente o ClientBasic
injeta diretamente o authProvider
na opção de Auth Proxy do Axios, porém tal opção permite apenas a passagem de um objeto JS com duas propriedades { username: string; password: string; }
.
// src/base.ts
class ClientBasic implements ClientBasicInterface {
clientOptions: ClientOptions;
client: AxiosInstance;
auth: object;
constructor(baseUrl: string, clientOptions: ClientOptions) {
this.clientOptions = clientOptions;
this.auth = {};
if (!this.clientOptions.timeout) this.clientOptions.timeout = 5000;
if (typeof this.clientOptions.retryDelay !== 'number')
this.clientOptions.retryDelay = 3;
if (typeof this.clientOptions.tries !== 'number')
this.clientOptions.tries = 0;
this.client = axios.create({
baseURL: baseUrl,
auth: this.clientOptions.authProvider // <- Injeção do Auth Provider
});
axiosRetry(this.client, {
retries: this.clientOptions.tries,
retryDelay: this.retryDelay,
retryCondition: this.retryCondition
});
}
// ...
}
Sendo assim seria necessário outra abordagem para garantir a execução correta dos Provedores de autenticação.
Segue o link da documentação do Axios sobre essa parte de autenticação: https://axios-http.com/docs/req_config