Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errorMessage: 'Authorization header string gönderilmesi zorunludur' #128

Open
SZaferUlgur opened this issue Apr 1, 2024 · 5 comments
Open

Comments

@SZaferUlgur
Copy link

[0] Sunucu 5000 nolu port üzerinde çalışıyor
[0] {
[0] status: 'failure',
[0] errorCode: '1009',
[0] errorMessage: 'Authorization header string gönderilmesi zorunludur',
[0] locale: 'tr',
[0] systemTime: 1712002834717,
[0] conversationId: '6386d0ea-ed16-40ed-a2bf-7c81658df463'
[0] }

axios.post(apiUrl, data, {
headers: {
"Content-Type": "application/json"
}
})
.then(response => {
const responseData = response.data;
console.log(responseData);
})
.catch(error => {
console.error('Hata:', error);
});

Cevap verebilir misiniz?

@SZaferUlgur
Copy link
Author

O bölümü aştık..
Bu linkteki https://docs.iyzico.com/on-hazirliklar/kimlik-dogrulama/sha1-kimlik-dogrulama
Şimdi de böyle bir şey çıktı..

[0] Sunucu 5000 nolu port üzerinde çalışıyor
[0] {
[0] status: 'failure',
[0] errorCode: '1004',
[0] errorMessage: 'Random string gönderilmesi zorunludur',
[0] locale: 'tr',
[0] systemTime: 1712005274112,
[0] conversationId: 'f27f3eb3-7d4e-4b8d-a9a2-4f6b089db07c'
[0] }

@aytaa
Copy link

aytaa commented Apr 26, 2024

O bölümü nasıl aştınız peki ?

@abdullah017
Copy link

Son aldığınız hatayı bende alıyorum bir çözüm bulabildiniz mi?

@alisahindev
Copy link

export const generateAuthorizationHeaderV2 = (uri, body) => {
  const iyziWsHeaderName = "IYZWSv2";
  const apiKey = process.env.IYZICO_API_KEY;
  const separator = ":";
  const secretKey = process.env.IYZICO_SECRET_KEY;
  const randomString = randomBytes(16).toString("hex");

  return (
    iyziWsHeaderName +
    " " +
    generateHashV2(apiKey, separator, uri, randomString, secretKey, body)
  );
};

export const generateHashV2 = (
  apiKey,
  separator,
  uri,
  randomString,
  secretKey,
  body
) => {
  const signature = createHmac("sha256", secretKey)
    .update(randomString + uri + JSON.stringify(body))
    .digest("hex");

  const authorizationParams = [
    "apiKey" + separator + apiKey,
    "randomKey" + separator + randomString,
    "signature" + separator + signature,
  ];
  return Buffer.from(authorizationParams.join("&")).toString("base64");
};
const iyzicoUrl = process.env.IYZICO_URL;

export const iyzico = axios.create({
  baseURL: iyzicoUrl,
});

export const post = async <T, R>(url: string, data: T) => {
  try {
    const response = await iyzico.post<T, AxiosResponse<R>>(url, data, {
      headers: {
        Authorization: generateAuthorizationHeaderV2(url, data),
      },
    });
    return response.data;
  } catch (error) {
    console.error("Error in API call:", error.response?.data || error.message);
    throw error;
  }
};

Buradaki kod parçası işinizi çözecektir, sağolsun iyzico geliştiricileri hiç bir şeye yardımcı olmadıkları için kendiniz over engineering yapmalısınız.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants