> For the complete documentation index, see [llms.txt](https://docs.morpara.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.morpara.com/entegrasyon-rehberi/quickstart.md).

# Kimlik Doğrulama

&#x20;Bu alan, entegrasyona başlamadan önce gerekli güvenlik ve kimlik doğrulama adımları hakkında temel bilgilere ulaşmanız için hazırlanmıştır.

MorPOS API’ları ile haberleşirken **SHA256 algoritması ile kimlik doğrulama** yapılması zorunludur. Aşağıdaki adımları takip ederek kimlik doğrulama mekanizmasını entegrasyonunuza dahil edebilirsiniz.

```
Base URL PROD: https://sale-gateway.morpara.com
```

```
Base URL Sandbox: https://finagopay-pf-api-gateway.prp.morpara.com
```

***

### 1) Headers

MorPOS Üye İşyeri Paneli > **Key Yönetimi** > **Key Tanıma** ekranına erişerek\
`ClientId` ve `ClientSecret` bilgilerinizi temin ediniz.

Bu bilgiler, yapacağınız tüm API çağrılarının **header** bilgileri içerisinde gönderilmelidir.

***

### 2) Request Sign

Herhangi bir API çağrısında, request gövdesi ile birlikte gönderilmesi gereken **sign** parametresi zorunludur.

Sign değeri şu şekilde üretilir:

* Request body’deki alanlar alınır
* Alt alta yazmak yerine **string olarak birleştirilir**
* Sonuna API Key eklenir
* SHA256 ile şifrelenir
* Base64 formatına çevrilip büyük harfe dönüştürülür
* Üretilen bu değer `sign` alanında API isteği ile gönderilir

```javascript
var CryptoJS = require("crypto-js");

let now = new Date();
let xTimestamp =
    now.getFullYear().toString() +
    String(now.getMonth() + 1).padStart(2, '0') +
    String(now.getDate()).padStart(2, '0') +
    String(now.getHours()).padStart(2, '0') +
    String(now.getMinutes()).padStart(2, '0') +
    String(now.getSeconds()).padStart(2, '0');

pm.environment.set("xTimestamp", xTimestamp);

const MrpApikey = "api_key_bilginiz";
const clientSecretKey = "client_secret_key_bilginiz";
const clientId = "client_id_bilginiz";
const MrpMerchantId = "merchant_id_bilginiz";

function generateRandomId(prefix, length) {
    const randomPart = Array(length)
        .fill(0)
        .map(() => Math.floor(Math.random() * 10))
        .join("");
    return `${prefix}${randomPart}`;
}

/*
ConversationId Kuralları

Alan zorunludur; null veya boş değer kabul edilmez.
Değer uzunluğu tam olarak 20 karakter olmalıdır.
Yalnızca İngilizce alfabetik karakterler (A-Z, a-z) ve rakamsal karakterler (0-9) kullanılabilir.
Türkçe karakter (ç, ğ, ı, İ, ö, ş, ü) kullanımına izin verilmez.
*/

const conversationId = generateRandomId("MSD", 17); 
const conversationIdPayment = generateRandomId("YSD", 17);


console.log("Client Secret",clientSecretKey);

const decodedClientSecret = CryptoJS.enc.Base64.parse(clientSecretKey).toString(CryptoJS.enc.Utf8);

console.log("Decoded Client Secret (UTF-8): ", decodedClientSecret);


const combined = decodedClientSecret + xTimestamp;
console.log("Combined Value (Decoded Client Secret + X-Timestamp): ", combined);


const sha256Hash = CryptoJS.SHA256(combined);
console.log("SHA256 Hash (Raw): ", sha256Hash.toString(CryptoJS.enc.Hex)); // 


const utf8Hash = CryptoJS.enc.Utf8.parse(sha256Hash.toString(CryptoJS.enc.Hex));
const finalEncoded = CryptoJS.enc.Base64.stringify(utf8Hash);
console.log("Final Encoded Hash (Base64, UTF-8): ", finalEncoded);


pm.variables.set("EncodedHash", finalEncoded);
pm.variables.set("MpConversationId", conversationId);
pm.variables.set("MpConversationIdPayment", conversationIdPayment);

let requestBodyDump = JSON.parse(pm.request.body);


const requestBody = {
...
};

function isNullOrWhiteSpace(str) {
    return !str || str.trim().length === 0;
}

function calculateDynamicHash(requestBody) {
    const concatenatedString = Object.values(requestBody)
        .map((value) => `${value}`) 
        .join(";"); 

    if (isNullOrWhiteSpace(concatenatedString))
        return false;

    const hash = CryptoJS.enc.Base64.stringify(CryptoJS.SHA256(CryptoJS.enc.Utf8.parse(concatenatedString))).toUpperCase();

    return hash;
}

const hashResult = calculateDynamicHash(requestBody);
    pm.variables.set("MpSign", hashResult);



```
