JWT Token Yapısı

Atlantic ID'nin ürettiği JWT token'ların yapısı, doğrulama yöntemleri ve kullanım rehberi.


Token Türleri

Access Token

  • Süre: 15 dakika (900 saniye)
  • Format: JWT (RS256)
  • Kullanım: API endpoint'lerine erişim
  • Header: Authorization: Bearer {access_token}

ID Token

  • Süre: 1 saat (3600 saniye)
  • Format: JWT (RS256)
  • Kullanım: Kullanıcı kimlik bilgileri
  • Doğrulama: Backend'de mutlaka doğrulanmalı

Refresh Token

  • Süre: 30 gün (2592000 saniye)
  • Format: Opak string (JWT değil)
  • Kullanım: Yeni access token almak

ID Token Yapısı

Header

```json { "alg": "RS256", "typ": "JWT", "kid": "atlantic_id_2024_rsa_key" } ```

Payload

```json { "iss": "https://id.codeatlantis.com", "sub": "550e8400-e29b-41d4-a716-446655440000", "aud": "cli_abc123", "exp": 1735689600, "iat": 1735686000, "auth_time": 1735686000, "nonce": "abc123", "name": "Görkem Yılmaz", "email": "gorkem@codeatlantis.com", "email_verified": true, "phone_number": "+905001234567", "amr": ["pwd", "otp"], "acr": "urn:codeatlantis:silver" } ```

Standard Claims

Claim Açıklama
iss Issuer - Her zaman https://id.codeatlantis.com
sub Subject - Kullanıcının unique UUID'si
aud Audience - Client ID
exp Expiration time - Unix timestamp
iat Issued at - Unix timestamp
auth_time Authentication time
nonce Authorization request'teki nonce

Profile Claims

Claim Scope Açıklama
name profile Tam ad
email email E-posta
email_verified email E-posta doğrulandı mı (her zaman true)
phone_number phone Telefon (E.164 format)
picture profile Avatar URL

Security Claims

Claim Açıklama
amr Authentication Methods: pwd, otp, webauthn
acr Authentication Context: bronze, silver, gold

Token Doğrulama

Node.js Örneği

```javascript const jwt = require('jsonwebtoken'); const jwksClient = require('jwks-rsa');

const client = jwksClient({ jwksUri: 'https://id.codeatlantis.com/oauth/jwks', cache: true, cacheMaxAge: 86400000 });

function getKey(header, callback) { client.getSigningKey(header.kid, (err, key) => { if (err) return callback(err); callback(null, key.getPublicKey()); }); }

jwt.verify(idToken, getKey, { issuer: 'https://id.codeatlantis.com', audience: 'cli_abc123', algorithms: ['RS256'] }, (err, decoded) => { if (err) { console.error('Invalid token:', err); } else { console.log('User:', decoded.email); } }); ```

Python Örneği

```python import jwt from jwt import PyJWKClient

jwks_client = PyJWKClient('https://id.codeatlantis.com/oauth/jwks') signing_key = jwks_client.get_signing_key_from_jwt(id_token)

decoded = jwt.decode( id_token, signing_key.key, algorithms=['RS256'], issuer='https://id.codeatlantis.com', audience='cli_abc123' ) ```

PHP Örneği

```php use Firebase\JWT\JWT; use Firebase\JWT\JWK;

$jwks = json_decode( file_get_contents('https://id.codeatlantis.com/oauth/jwks'), true ); $keys = JWK::parseKeySet($jwks);

$decoded = JWT::decode($idToken, $keys);

if ($decoded->iss !== 'https://id.codeatlantis.com') { throw new Exception('Invalid issuer'); } ```


Token Yenileme

```javascript const response = await fetch('https://id.codeatlantis.com/oauth/token', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams({ grant_type: 'refresh_token', refresh_token: storedRefreshToken, client_id: 'cli_abc123' }) });

const { access_token, id_token, refresh_token } = await response.json(); ```


Güvenlik Best Practices

✅ Yapın

  1. Backend'de doğrulayın
  2. İmzayı kontrol edin (JWKS)
  3. iss, aud, exp doğrulayın
  4. httpOnly cookie'de saklayın
  5. HTTPS kullanın

❌ Yapmayın

  1. Frontend'de güvenmeyin
  2. LocalStorage kullanmayın
  3. URL'de göndermeyin
  4. İmzayı atlamayın
  5. alg: none kabul etmeyin

Detaylı implementation için SDK Örnekleri sayfasına bakın.