Commit 8dfcca5
authored
feat(auth): generic external SSO / OIDC login + refresh-token sessions + docs (#328)
* feat(auth): add generic external SSO / OIDC login provider (#327)
Delegate PoracleWeb login to any external OAuth2/OpenID Connect provider, alongside the built-in Discord and Telegram methods. Enables single sign-on (e.g. pointing PoracleWeb at the PogoAlerts OAuth2 server) while staying provider-agnostic so any self-hoster can configure their own IdP.
Implemented as a configurable twin of the Discord flow:
- OidcSettings (URLs, client id/secret, scopes, claim mapping, PKCE flag)
- GET /api/auth/oidc/login + /callback: auth-code exchange with PKCE, CSRF state in HttpOnly cookies; reads a configurable identity claim (default discord_id, falls back to sub), looks it up in the human table, reuses GetRolesAsync + guild-role gating, mints the existing internal JWT
- providers endpoint gains an oidc block; enable_oidc site-setting runtime toggle (admins can always log in to re-enable); OIDC_* env bridge with auto-infer; documented in .env.example
- Frontend: oidc provider model, loginWithOidc(), /auth/oidc/callback route, login button + disabled hint + error codes, admin External SSO group, English i18n keys
Tests: backend providers oidc block + /oidc/login redirect/PKCE (1394 pass); frontend OIDC button visibility + click delegation (48 pass).
* feat(auth): OIDC refresh-token sessions, SSO refinements, and docs
Optional, provider-agnostic consumption of the external SSO provider's refresh
token for silent session renewal + revocation propagation (default OFF via
OIDC_USE_REFRESH_TOKENS), plus surrounding SSO login refinements and a
comprehensive OIDC documentation set. Fully OIDC-provider-agnostic; PogoAlerts
is only the reference provider.
Backend:
- oidc_sessions table (EF migration AddOidcSessions): the provider refresh token
is stored server-side, DataProtection-encrypted, never sent to the browser; the
browser holds only an opaque rotating token keyed to a rotation family.
- POST /api/auth/oidc/refresh (rotate + live user re-validation + family-revoke on
replay/provider-revoke) and /oidc/refresh/revoke; OidcSessionCleanupService reaps
expired/stale rows (OIDC_SESSION_REVOKED_RETENTION_DAYS, default 2).
- Provider-agnostic IOidcClient shared by login callback and refresh: configurable
client_secret_post|client_secret_basic, optional/non-rotating refresh tokens,
offline_access auto-appended; no discovery/JWKS/id_token dependency.
- Per-login short JWT for refresh-backed OIDC sessions (OIDC_ACCESS_TOKEN_MINUTES,
default 30); Discord/Telegram/local logins keep the 24h JWT.
- Refresh is env-controlled only (no runtime admin toggle — coupled to JWT lifetime).
Frontend:
- TokenStoreService (single-flight refresh) + oidcRefreshInterceptor (proactive
pre-expiry + reactive 401-retry, null-refresh-token guard so non-refresh logins
keep the existing 401->logout path); callback stores the opaque token; logout
revokes the session server-side.
- SSO login refinements: Local/SSO auth-mode switch, single-logout toggle,
auto-redirect + signed-out panel, i18n.
Docs (MkDocs / gh-pages):
- New "External SSO (OIDC)" setup page + reworked "OIDC Refresh Tokens" page
(Mermaid flows, security model, provider matrix: Keycloak/Authentik/Auth0/
Google/Azure-Entra/Okta/PogoAlerts).
- OIDC env vars added to the Configuration Reference, enable_oidc/enable_oidc_slo
to Site Settings, an OIDC troubleshooting section, and nav entries.
Tests: xUnit (session rotation/replay/cap/cleanup over SQLite, provider-agnostic
client, providers/callback) + Jest (token-store single-flight, interceptor
proactive/reactive/loop-guard). Backend 1422 pass, frontend 872 pass.1 parent 0310c56 commit 8dfcca5
60 files changed
Lines changed: 5048 additions & 346 deletions
File tree
- Applications
- Pgan.PoracleWebNet.Api
- Configuration
- Controllers
- Services/Oidc
- Pgan.PoracleWebNet.App/ClientApp
- src
- app
- core
- interceptors
- models
- services
- modules
- admin
- auth
- assets/i18n
- Core
- Pgan.PoracleWebNet.Core.Abstractions/Repositories
- Pgan.PoracleWebNet.Core.Models
- Pgan.PoracleWebNet.Core.Repositories
- Pgan.PoracleWebNet.Core.Services
- Data/Pgan.PoracleWebNet.Data
- Configurations
- Entities
- Migrations/PoracleWeb
- Tests/Pgan.PoracleWebNet.Tests
- Controllers
- Repositories
- Services
- docs
- configuration
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
78 | 121 | | |
79 | 122 | | |
80 | 123 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
18 | 25 | | |
19 | 26 | | |
20 | 27 | | |
| |||
Lines changed: 10 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
36 | 42 | | |
37 | 43 | | |
38 | 44 | | |
| |||
88 | 94 | | |
89 | 95 | | |
90 | 96 | | |
91 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
92 | 100 | | |
93 | 101 | | |
94 | 102 | | |
| |||
97 | 105 | | |
98 | 106 | | |
99 | 107 | | |
100 | | - | |
| 108 | + | |
101 | 109 | | |
102 | 110 | | |
103 | 111 | | |
| |||
Lines changed: 115 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| |||
149 | 150 | | |
150 | 151 | | |
151 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
152 | 158 | | |
153 | 159 | | |
154 | 160 | | |
155 | 161 | | |
156 | 162 | | |
157 | 163 | | |
158 | 164 | | |
| 165 | + | |
159 | 166 | | |
160 | 167 | | |
161 | 168 | | |
| |||
0 commit comments