Histórico de mensagens sobre credentials em devs

EXIBINDO CONVERSAS RECENTES:

Texto: credentials
Canal: devs
Avatar discord do usuario thomasmendonca

thomasmendonca

Ver Respostas

Mas quando tento fazer a requisição dá erro: "Could not authenticate. Please make sure you are using correct credentials and if you are using then in the correct environment"

Avatar discord do usuario calhau9644

calhau9644

Ver Respostas

Boa tarde pessoal,

Estou tentando fazer uma chamada Post no endpoint https://pix-h.api.efipay.com.br/oauth/token pelo INSOMNIA.

Ja configurei o certificado PFX or PKCS12.

Ja adicionei no body da requisicao o

{
"grant_type": "client_credentials"
}

E ja adicionei tambem no Auth Basic o Username = ClientID e Password = Client_SECRET

Porem estou tendo o erro abaixo.

{
"error": "invalid_client",
"error_description": "Invalid or inactive credentials"
}

Alguem poderia me ajudar o que posso esta fazendo errado?

Avatar discord do usuario cleyton5212

cleyton5212

Ver Respostas

class Gerencianet:
"""Classe para pagamento do Gerencianet."""

def __init__(self, credentials: GerencianetCredentials):
self.header = {}
self.credentials = credentials
self.cert = credentials.cert
self.payment_id = None
self.status_payment = None
self.key_pix = credentials.key_pix
self.user_id = None
self.hc = credentials.hc
self.c = "GerenciaNet"

async def create_payment(
self,
value: Union[int, float] = 0.0,
time: int = 30,
cpf: str = "",
name: str = "",
user_id: int = 0,
):
token = await self.credentials.token()
header = {
"Authorization": f"Bearer {token}",
}

Avatar discord do usuario russofullstack

russofullstack

posso subir em outro servidor e mandar o caminho no obj credentials?

Avatar discord do usuario joaolucas_efi

joaolucas_efi

Ver Respostas

@jonadabir há uma falha na forma com que você está montando a requisição.

Ela deve ser da seguinte forma:

js
const certificatePath = path.join(
__dirname,
'../../../certificates/pix_certificate.p12',
);

const certificate = fs.readFileSync(certificatePath);

const getPixAuthorization = async () => {
const agent = new https.Agent({
pfx: certificate,
passphrase: '',
});

let authParams = {
method: 'POST',
url: 'https://pix-h.api.efipay.com.br/oauth/token',
data: {
grant_type: 'client_credentials',
},
httpsAgent: agent,
};
let token = Buffer.from(credentials.client_id + ':' + credentials.client_secret).toString('base64')
authParams.headers['Authorization'] = 'Basic ' + token
authParams.headers['Content-Type'] = 'application/json'
const authRes = await axios(authParams);

return authRes.data;
};

Avatar discord do usuario jonadabir

jonadabir

Ver Respostas

estou tentando fazer a req de obter autorização PIX porem estou recebendo o seguinte erro:

ts
cause: Error: socket hang up
at TLSSocket.socketOnEnd (node:_http_client:524:23)
at TLSSocket.emit (node:events:531:35)
at endReadableNT (node:internal/streams/readable:1696:12)
at processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: 'ECONNRESET'
}
Meu código:
ts
const certificatePath = path.join(
__dirname,
'../../../certificates/pix_certificate.p12',
);

const certificate = fs.readFileSync(certificatePath);

const getPixAuthorization = async () => {
const agent = new https.Agent({
pfx: certificate,
passphrase: '',
});

const authParams = {
method: 'POST',
url: 'https://pix-h.api.efipay.com.br/oauth/token',
auth: {
username: credentials.client_id,
password: credentials.client_secret,
},
data: {
grant_type: 'client_credentials',
},
httpsAgent: agent,
};

const authRes = await axios(authParams);

return authRes.data;
};

Avatar discord do usuario joaolucas_efi

joaolucas_efi

Ver Respostas

Bom dia, @jonadabir, tudo bem?
A autenticação para a API de cobranças deve ser algo da seguinte forma

js
async authenticate() {
let authParams = {
method: 'POST',
url: 'https://cobrancas-h.api.efipay.com.br/v1/authorize',
auth: {
username: credentials.client_id,
password: credentials.client_secret,
},
data: {
grant_type: 'client_credentials',
},
}
return axios(authParams)
.then((res) => {
this.auth = res.data
this.auth.authDate = new Date().getTime() / 1000
})
.catch((error) => {
throw error.data
})
}

Avatar discord do usuario jonadabir

jonadabir

Ver Respostas

Bom dia! Estou tentando fazer a requisiçao de obter a autorizaçao no node igual na documentaçao, porem estou tomando um 401

ts
const credentials = {
client_id: process.env.EFI_CLIENT_ID,
client_secret: process.env.EFI_CLIENT_SECRET,
};

export const getCobrancasAuthorization = async () => {
const data = JSON.stringify({ grant_type: 'client_credentials' });
const data_credentials =
credentials.client_id + ':' + credentials.client_secret;

const auth = Buffer.from(data_credentials).toString('base64');

const config = {
method: 'POST',
url: 'https://cobrancas-h.api.efipay.com.br/v1/authorize',
headers: {
Authorization: 'Basic ' + auth,
'Content-Type': 'application/json',
},
data: data,
};

try {
const response = await axios(config);
return response.data;
} catch (error) {
console.log(error);
}
};

Avatar discord do usuario danielsouza1283

danielsouza1283

Ver Respostas

O token se gera com Basic, certo?
$credentials = base64_encode($options["clientId"] . ":" . $options["clientSecret"]);
$headers = [
"Authorization" => "Basic " . $credentials,
"Content-Type: application/json"
];