Auth Controller — Kimlik Doğrulama API'si
Base Route: /api/auth
Service: Taz.SaaS.Identity.API
Aşağıdaki endpoint'ler OAuth2/OIDC tabanlı kimlik doğrulama akışlarını yönetir. Taz.SaaS.Identity.Application katmanında MediatR CQRS pattern uygulanır; Command sınıfları (LoginCommand, RegisterCommand, vb.) ile request validation, DTO mapping ve error handling sağlanır.
1. Register
HTTP Method: POST
Route: /api/auth/register
Authentication: NotRequired
Yeni kullanıcı hesabı oluşturur ve email doğrulama kodu gönderir. RegisterCommandValidator ile email format, password strength kuralları validasyonu yapılır.
Request Body
{
"email": "string (required)",
"password": "string (required, min 8 chars, must include uppercase, lowercase, digit)",
"firstName": "string (required)",
"lastName": "string (required)",
"phoneNumber": "string | null"
}
Response
Status Code: 201 Created
{
"success": true,
"result": {
"id": "guid",
"email": "string",
"isActive": true
}
}
Status Code: 400 Bad Request
{
"success": false,
"error": {
"code": "string (e.g., DUPLICATE_EMAIL)",
"message": "string"
}
}
2. Login — E-posta/Şifre
HTTP Method: POST
Route: /api/auth/login
Authentication: NotRequired
E-posta ve şifre ile oturum açar. LoginCommandHandler kullanıcı doğrulaması yapar, JWT access + refresh token üretir (JwtTokenService). Login sonrası TenantStatusCheckMiddleware tenant durumunu kontrol eder (aktif/beklemede/blokeli).
Request Body
{
"email": "string (required)",
"password": "string (required)",
"rememberMe": "boolean (optional, default: false)"
}
Response
Status Code: 200 OK — AuthenticationResult DTO dönüşü.
{
"success": true,
"result": {
"accessToken": "string (JWT)",
"refreshToken": "string",
"expiresIn": 3600,
"user": {
"id": "guid",
"email": "string",
"firstName": "string",
"lastName": "string",
"roles": ["string[]"],
"tenantId": "guid | null",
"permissions": ["string[]"],
"avatarUrl": "string | null"
},
"requiredEmailVerification": false
}
}
Status Code: 401 Unauthorized
{
"success": false,
"error": {
"code": "INVALID_CREDENTIALS",
"message": "Geçersiz e-posta veya şifre."
}
}
3. Login — Google (OAuth2)
HTTP Method: POST
Route: /api/auth/login/google
Authentication: NotRequired
Google OAuth2 akışını başlatır. ExternalLoginCommandHandler → GoogleAuthService.GetGoogleAuthorizationUrl() Google'ın authorization URL'sini döndürür. Frontend bu URL'ye redirect eder, callback ile code parametresi alınır.
Request Body
{
"redirectUri": "string (required)"
}
Response
Status Code: 200 OK
{
"success": true,
"result": {
"authorizationUrl": "string (Google OAuth2 URL)",
"state": "string (CSRF koruma için random state)",
"clientId": "string"
}
}
4. Login — Google Callback
HTTP Method: POST
Route: /api/auth/login/google/callback
Authentication: NotRequired
Google'dan code alarak token exchange yapar, kullanıcı kaydı/sorgusu sonrası JWT üretir. GoogleAuthService.ExchangeCodeAsync(code) erişim token'ını alır, profil bilgilerini çeker.
Request Body
{
"code": "string (required, Google authorization code)",
"redirectUri": "string (required)"
}
Response
Status Code: 200 OK — Login ile aynı AuthenticationResult yapısı.
5. Login — Microsoft OAuth2
HTTP Method: POST
Route: /api/auth/login/microsoft
Authentication: NotRequired
Microsoft Azure AD OAuth2 akışı başlatır. MicrosoftAuthService.GetMicrosoftAuthorizationUrl() kullanılır.
Request Body
{
"redirectUri": "string (required)"
}
Response
Status Code: 200 OK
{
"success": true,
"result": {
"authorizationUrl": "string",
"state": "string",
"clientId": "string"
}
}
6. Login — Microsoft Callback
HTTP Method: POST
Route: /api/auth/login/microsoft/callback
Authentication: NotRequired
Microsoft OAuth2 callback ile token exchange + JWT üretimi.
Request Body
{
"code": "string (required)",
"state": "string (required)",
"redirectUri": "string (required)"
}
Response
Status Code: 200 OK — AuthenticationResult DTO.
7. Refresh Token
HTTP Method: POST
Route: /api/auth/refresh-token
Authentication: Required (Bearer token)
Refresh token ile yeni access + refresh token set'i üretir. JwtTokenService.RefreshToken() tarafından yapılır. Eski refresh token devre dışı bırakılır.
Request Body
{
"accessToken": "string (required)",
"refreshToken": "string (required)"
}
Response
Status Code: 200 OK
{
"success": true,
"result": {
"accessToken": "string",
"refreshToken": "string",
"expiresIn": 3600
}
}
8. Forgot Password
HTTP Method: POST
Route: /api/auth/forgot-password
Authentication: NotRequired
Şifre sıfırlama linki/ kodu e-posta ile gönderir. ForgotPasswordCommandHandler random token üretir, IdentityDbContext'te saklar, EmailVerificationService ile mail gönderir.
Request Body
{
"email": "string (required)"
}
Response
Status Code: 200 OK
{
"success": true,
"result": null
}
Not: Hesap varsa şifre sıfırlama linki gönderilir. Güvenlik için hesap yoksa bile 200 döner (enumeration koruma).
9. Reset Password
HTTP Method: POST
Route: /api/auth/reset-password
Authentication: NotRequired
Token ile şifre sıfırlama. ResetPasswordCommandHandler token validasyonu + newPassword strength kontrolü yapar.
Request Body
{
"email": "string (required)",
"resetToken": "string (required)",
"newPassword": "string (required, min 8 chars)"
}
Response
Status Code: 200 OK
{
"success": true,
"result": null
}
10. Verify Email
HTTP Method: POST
Route: /api/auth/verify-email
Authentication: NotRequired
Kayıt sonrası gelen email doğrulama kodunu teyit eder. VerifyEmailCommandHandler token validasyonu + User.emailConfirmed = true.
Request Body
{
"email": "string (required)",
"code": "string (required, 6-digit verification code)"
}
Response
Status Code: 200 OK
{
"success": true,
"result": null
}
11. Resend Verification Code
HTTP Method: POST
Route: /api/auth/resend-verification
Authentication: NotRequired
Doğrulama kodunu tekrar gönderir (rate-limited: 60sn aralık).
Request Body
{
"email": "string (required)"
}
Response
Status Code: 200 OK
{
"success": true,
"result": null
}
12. Change Password
HTTP Method: POST
Route: /api/auth/change-password
Authentication: Required (Bearer token)
Mevcut şifreyi doğrulayıp yeni şifre set eder. AuthRateLimitMiddleware ile rate limiting uygulanır.
Request Body
{
"currentPassword": "string (required)",
"newPassword": "string (required, min 8 chars)"
}
Response
Status Code: 200 OK
{
"success": true,
"result": null
}
13. Logout
HTTP Method: POST
Route: /api/auth/logout
Authentication: Required (Bearer token)
Refresh token'ı devre dışı bırakır (RefreshTokenRepository.InvalidateAsync()).
Request Body
{
"refreshToken": "string (required)"
}
Response
Status Code: 204 No Content