Kimlik Doğrulama
SeoAuthor API, güvenlik için JWT (JSON Web Token) tabanlı kimlik doğrulama sistemi kullanır. Bu sistem, modern web uygulamalarında yaygın olarak kullanılan güvenli bir yöntemdir.
🔐 Kimlik Doğrulama Akışı
sequenceDiagram
participant Client
participant API
Client->>API: 1. Login (email/password)
API-->>Client: 2. Access Token + Refresh Token
Client->>API: 3. API Calls (Bearer Token)
API-->>Client: 4. Data Response
Note over Client,API: Token süresi dolduğunda
Client->>API: 5. Refresh Token
API-->>Client: 6. New Access Token
🎫 Token Türleri
Access Token
- Süre: Kısa süreli (60 dakika)
- Kullanım: API çağrıları için Authorization header'ında
- Format:
Bearer YOUR_ACCESS_TOKEN
Refresh Token
- Süre: Uzun süreli (30 gün)
- Kullanım: Yeni access token almak için
- Güvenlik: Güvenli bir şekilde saklanmalı
📋 Authentication Endpoints
| Endpoint | Method | Açıklama |
|---|---|---|
/api/v1/auth/login | POST | Giriş yapma |
/api/v1/auth/refresh | POST | Token yenileme |
🔑 Giriş Yapma
Sisteme giriş yapmak için email ve şifrenizi kullanın.
Request
POST /api/v1/auth/login
Content-Type: application/json
{
"email": "string",
"password": "string"
}
Request Body Schema
| Alan | Tip | Zorunlu | Açıklama |
|---|---|---|---|
email | string | ✅ | Kayıtlı email adresiniz |
password | string | ✅ | Hesap şifreniz |
Response
{
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"accessTokenExpire": 1692789600,
"refreshToken": "def502004b8f5b592c4f6c94def50200..."
}
Response Schema
| Alan | Tip | Açıklama |
|---|---|---|
accessToken | string | API çağrıları için kullanılacak token |
accessTokenExpire | integer | Token'ın sona erme zamanı (Unix timestamp) |
refreshToken | string | Yeni access token almak için kullanılacak token |
Örnek Kodlar
JavaScript/Node.js
async function login(email, password) {
try {
const response = await fetch(
"https://integration.seoauthor.ai/api/v1/auth/login",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: email,
password: password,
}),
}
);
if (!response.ok) {
throw new Error("Login failed");
}
const data = await response.json();
// Token'ları güvenli bir şekilde sakla
localStorage.setItem("accessToken", data.accessToken);
localStorage.setItem("refreshToken", data.refreshToken);
return data;
} catch (error) {
console.error("Login error:", error);
throw error;
}
}
Python
import requests
import json
def login(email, password):
url = "https://integration.seoauthor.ai/api/v1/auth/login"
headers = {
"Content-Type": "application/json"
}
data = {
"email": email,
"password": password
}
try:
response = requests.post(url, headers=headers, json=data)
response.raise_for_status()
auth_data = response.json()
# Token'ları güvenli bir şekilde sakla
# Örnek: environment variables veya secure storage
return auth_data
except requests.exceptions.RequestException as e:
print(f"Login error: {e}")
raise
PHP
<?php
function login($email, $password) {
$url = 'https://integration.seoauthor.ai/api/v1/auth/login';
$data = [
'email' => $email,
'password' => $password
];
$options = [
'http' => [
'header' => "Content-type: application/json\r\n",
'method' => 'POST',
'content' => json_encode($data)
]
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {
throw new Exception('Login failed');
}
return json_decode($result, true);
}
?>
🔄 Token Yenileme
Access token'ınızın süresi dolduğunda, refresh token kullanarak yeni bir access token alabilirsiniz.
Request
POST /api/v1/auth/refresh
Content-Type: application/json
{
"refreshToken": "string"
}
Request Body Schema
| Alan | Tip | Zorunlu | Açıklama |
|---|---|---|---|
refreshToken | string | ✅ | Daha önce alınan refresh token |
Response
{
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"accessTokenExpire": 1692789600,
"refreshToken": "def502004b8f5b592c4f6c94def50200..."
}
Örnek Kod
async function refreshToken(refreshToken) {
try {
const response = await fetch(
"https://integration.seoauthor.ai/api/v1/auth/refresh",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
refreshToken: refreshToken,
}),
}
);
if (!response.ok) {
throw new Error("Token refresh failed");
}
const data = await response.json();
// Yeni token'ları sakla
localStorage.setItem("accessToken", data.accessToken);
localStorage.setItem("refreshToken", data.refreshToken);
return data;
} catch (error) {
console.error("Token refresh error:", error);
// Refresh token da geçersizse, kullanıcıyı yeniden login'e yönlendir
throw error;
}
}
🔒 API Çağrılarında Token Kullanımı
Access token'ı aldıktan sonra, tüm API çağrılarında Authorization header'ında kullanmalısınız.
Authorization Header Format
Authorization: Bearer YOUR_ACCESS_TOKEN
Örnek API Çağrısı
const accessToken = localStorage.getItem("accessToken");
fetch("https://integration.seoauthor.ai/api/v1/profil/guncel-bakiye", {
method: "GET",
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
})
.then((response) => response.json())
.then((data) => console.log(data));
⚠️ Hata Durumları
400 Bad Request
- Geçersiz email formatı
- Eksik parametreler
- Yanlış şifre
401 Unauthorized
- Geçersiz token
- Süresi dolmuş token
- Eksik Authorization header
Örnek Hata Yanıtı
{
"error": "Invalid credentials",
"message": "Email or password is incorrect",
"statusCode": 400
}
🛡️ Güvenlik En İyi Uygulamaları
✅ Yapılması Gerekenler
- Token'ları güvenli bir şekilde saklayın (HTTPS, secure storage)
- Token sürelerini düzenli olarak kontrol edin
- Refresh token'ı sunucu tarafında saklayın
- Environment variables kullanın
❌ Yapılmaması Gerekenler
- Token'ları URL'de göndermeyin
- Token'ları client-side JavaScript'te saklamayın
- Token'ları log dosyalarına yazmayın
- Güvensiz bağlantılarda (HTTP) token göndermeyin