Penanganan Error
Kode error OAuth 2.1 dan troubleshooting umum.
Error Codes OAuth 2.1
| Error Code | HTTP Status | Keterangan |
|---|---|---|
invalid_request | 400 | Request tidak valid (parameter hilang/salah) |
invalid_client | 401 | Client authentication gagal |
invalid_grant | 400 | Authorization code/refresh token tidak valid |
unauthorized_client | 401 | Client tidak diizinkan untuk grant type ini |
access_denied | 403 | User menolak consent |
unsupported_response_type | 400 | Response type tidak didukung |
invalid_scope | 400 | Scope tidak valid |
server_error | 500 | Error internal server |
Contoh Error Response
{
"error": "invalid_grant",
"error_description": "The authorization code has expired"
}Troubleshooting
Error: invalid_client
Penyebab:
- Client ID atau Client Secret salah
- Client tidak terdaftar
Solusi:
- Verifikasi Client ID dan Secret
- Hubungi administrator untuk konfirmasi
Error: invalid_grant
Penyebab:
- Authorization code sudah digunakan
- Authorization code sudah expired
- Code verifier tidak cocok dengan code challenge
- Redirect URI tidak cocok
Solusi:
- Mulai ulang flow OAuth dari awal
- Pastikan code_verifier yang disimpan benar
- Verifikasi redirect_uri sama persis
Error: validasi ID token gagal (iss / signature)
Penyebab:
- Issuer di client diset ke origin (
https://bukutamu.tabalongkab.go.id) tanpa/api/auth - Library mengasumsikan algoritma
RS256padahal ID token memakai EdDSA - JWKS URL salah
Solusi:
- Set issuer ke
https://bukutamu.tabalongkab.go.id/api/auth - Ambil JWKS dari
https://bukutamu.tabalongkab.go.id/api/auth/jwks - Lebih aman: pakai OIDC discovery di
/.well-known/openid-configuration
Error: invalid_scope
Penyebab:
- Scope yang diminta tidak diizinkan untuk client ini
- Typo pada nama scope
Solusi:
- Periksa scope yang didaftarkan untuk client
- Gunakan scope yang tercantum di dokumentasi
Error: access_denied
Penyebab:
- User menolak memberikan consent
Solusi:
- Tampilkan pesan yang informatif ke user
- Berikan opsi untuk mencoba lagi