mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-04 00:26:07 +02:00
207 lines
8.8 KiB
HTML
207 lines
8.8 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Authentication | EchoHub Documentation </title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta name="title" content="Authentication | EchoHub Documentation ">
|
|
|
|
|
|
<link rel="icon" href="../images/hue_icon.svg">
|
|
<link rel="stylesheet" href="../public/docfx.min.css">
|
|
<link rel="stylesheet" href="../public/main.css">
|
|
<meta name="docfx:navrel" content="../toc.html">
|
|
<meta name="docfx:tocrel" content="../articles/toc.html">
|
|
|
|
<meta name="docfx:rel" content="../">
|
|
|
|
|
|
<meta name="docfx:docurl" content="https://github.com/HueByte/EchoHub/blob/master/docs/#L1">
|
|
<meta name="loc:inThisArticle" content="In this article">
|
|
<meta name="loc:searchResultsCount" content="{count} results for "{query}"">
|
|
<meta name="loc:searchNoResults" content="No results for "{query}"">
|
|
<meta name="loc:tocFilter" content="Filter by title">
|
|
<meta name="loc:nextArticle" content="Next">
|
|
<meta name="loc:prevArticle" content="Previous">
|
|
<meta name="loc:themeLight" content="Light">
|
|
<meta name="loc:themeDark" content="Dark">
|
|
<meta name="loc:themeAuto" content="Auto">
|
|
<meta name="loc:changeTheme" content="Change theme">
|
|
<meta name="loc:copy" content="Copy">
|
|
<meta name="loc:downloadPdf" content="Download PDF">
|
|
|
|
<script type="module" src="./../public/docfx.min.js"></script>
|
|
|
|
<script>
|
|
const theme = localStorage.getItem('theme') || 'auto'
|
|
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body class="tex2jax_ignore" data-layout="" data-yaml-mime="">
|
|
<header class="bg-body border-bottom">
|
|
<nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
|
|
<div class="container-xxl flex-nowrap">
|
|
<a class="navbar-brand" href="../index.html">
|
|
<img id="logo" class="svg" src="../images/hue_icon.svg" alt="EchoHub">
|
|
EchoHub
|
|
</a>
|
|
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
|
|
<i class="bi bi-three-dots"></i>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navpanel">
|
|
<div id="navbar">
|
|
<form class="search" role="search" id="search">
|
|
<i class="bi bi-search"></i>
|
|
<input class="form-control" id="search-query" type="search" disabled placeholder="Search" autocomplete="off" aria-label="Search">
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
</header>
|
|
|
|
<main class="container-xxl">
|
|
<div class="toc-offcanvas">
|
|
<div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
|
|
<div class="offcanvas-header">
|
|
<h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
|
|
</div>
|
|
<div class="offcanvas-body">
|
|
<nav class="toc" id="toc"></nav>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="content">
|
|
<div class="actionbar">
|
|
<button class="btn btn-lg border-0 d-md-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
|
|
<i class="bi bi-list"></i>
|
|
</button>
|
|
|
|
<nav id="breadcrumb"></nav>
|
|
</div>
|
|
|
|
<article data-uid="">
|
|
<h1 id="authentication">Authentication</h1>
|
|
|
|
<h2 id="user-registration">User Registration</h2>
|
|
<p>A new user creates an account on a server. The client sends credentials via REST,
|
|
the server hashes the password, issues JWT tokens, and the client stores the
|
|
refresh token for "Remember Me" sessions.</p>
|
|
<pre><code class="lang-mermaid">sequenceDiagram
|
|
participant UI as ConnectDialog
|
|
participant AO as AppOrchestrator
|
|
participant CM as ConnectionManager
|
|
participant API as ApiClient
|
|
participant Auth as AuthController
|
|
participant US as UserService
|
|
participant JWT as JwtTokenService
|
|
participant DB as SQLite
|
|
|
|
UI->>AO: ConnectDialogResult(IsRegister: true)
|
|
AO->>CM: ConnectAsync(dialogResult)
|
|
CM->>API: RegisterAsync(username, password)
|
|
API->>Auth: POST /api/auth/register
|
|
Auth->>US: RegisterUserAsync(username, password, displayName)
|
|
US->>US: Validate (regex, length, uniqueness)
|
|
US->>DB: INSERT User (BCrypt hash)
|
|
US-->>Auth: UserOperationResult.Success
|
|
Auth->>JWT: GenerateAccessToken(user)
|
|
JWT-->>Auth: (token, expiresAt) [15 min]
|
|
Auth->>JWT: GenerateRefreshToken()
|
|
JWT-->>Auth: Base64 random (64 bytes)
|
|
Auth->>DB: INSERT RefreshToken (SHA256 hash)
|
|
Auth-->>API: LoginResponse
|
|
API->>API: SetTokens() — store in memory + set Bearer header
|
|
API-->>CM: LoginResponse
|
|
CM->>CM: Wire OnTokensRefreshed for config persistence
|
|
CM->>CM: Continue to connection setup (see Connection Flow)
|
|
</code></pre>
|
|
<hr>
|
|
<h2 id="user-login">User Login</h2>
|
|
<p>Returning user authenticates with username/password or a saved refresh token.</p>
|
|
<pre><code class="lang-mermaid">sequenceDiagram
|
|
participant UI as ConnectDialog
|
|
participant CM as ConnectionManager
|
|
participant API as ApiClient
|
|
participant Auth as AuthController
|
|
participant US as UserService
|
|
participant DB as SQLite
|
|
|
|
alt Saved refresh token (Remember Me)
|
|
UI->>CM: ConnectDialogResult(SavedRefreshToken: "...")
|
|
CM->>API: LoginWithRefreshTokenAsync()
|
|
API->>Auth: POST /api/auth/refresh
|
|
Auth->>DB: Lookup token by SHA256 hash
|
|
Auth->>DB: Revoke old token, issue new pair
|
|
Auth-->>API: LoginResponse (rotated tokens)
|
|
else Username + Password
|
|
UI->>CM: ConnectDialogResult(IsRegister: false)
|
|
CM->>API: LoginAsync(username, password)
|
|
API->>Auth: POST /api/auth/login
|
|
Auth->>US: AuthenticateUserAsync(username, password)
|
|
US->>DB: Fetch user, BCrypt.Verify(password, hash)
|
|
US->>DB: Update LastSeenAt
|
|
US-->>Auth: UserOperationResult.Success
|
|
Auth-->>API: LoginResponse
|
|
end
|
|
API->>API: SetTokens()
|
|
</code></pre>
|
|
<hr>
|
|
<h2 id="token-refresh">Token Refresh</h2>
|
|
<p>Access tokens expire after 15 minutes. The client auto-refreshes transparently
|
|
before requests and on 401 responses. Refresh tokens are rotated on each use.</p>
|
|
<pre><code class="lang-mermaid">sequenceDiagram
|
|
participant SR as SignalR / HTTP Request
|
|
participant API as ApiClient
|
|
participant Auth as AuthController
|
|
participant DB as SQLite
|
|
participant Config as config.json
|
|
|
|
SR->>API: GetValidTokenAsync() or HTTP 401
|
|
API->>API: Token expires within 60s?
|
|
alt Proactive refresh (SignalR token provider)
|
|
API->>Auth: POST /api/auth/refresh (old refresh token)
|
|
else Reactive refresh (HTTP 401 retry)
|
|
API->>Auth: POST /api/auth/refresh (old refresh token)
|
|
end
|
|
Auth->>DB: Lookup by SHA256 hash
|
|
Auth->>DB: Revoke old refresh token
|
|
Auth->>DB: INSERT new RefreshToken
|
|
Auth-->>API: LoginResponse (new token pair)
|
|
API->>API: SetTokens() — update Bearer header
|
|
API-->>API: Fire OnTokensRefreshed event
|
|
API-->>Config: Persist new refresh token (if Remember Me)
|
|
API->>SR: Retry original request with new token
|
|
</code></pre>
|
|
|
|
</article>
|
|
|
|
<div class="contribution d-print-none">
|
|
<a href="https://github.com/HueByte/EchoHub/blob/master/docs/#L1" class="edit-link">Edit this page</a>
|
|
</div>
|
|
|
|
<div class="next-article d-print-none border-top" id="nextArticle"></div>
|
|
|
|
</div>
|
|
|
|
<div class="affix">
|
|
<nav id="affix"></nav>
|
|
</div>
|
|
</main>
|
|
|
|
<div class="container-xxl search-results" id="search-results"></div>
|
|
|
|
<footer class="border-top text-secondary">
|
|
<div class="container-xxl">
|
|
<div class="flex-fill">
|
|
<div class='footer-custom'><div class='footer-inner'><span class='footer-brand'>EchoHub</span><span class='footer-sep'>·</span><a href='https://github.com/HueByte/EchoHub'>GitHub</a><span class='footer-sep'>·</span><a href='https://echohub.voidcube.cloud'>Website</a></div></div>
|
|
</div>
|
|
</div>
|
|
</footer>
|
|
</body>
|
|
</html>
|