Login with HdSpace
HdSpace Account is a standard OpenID Connect provider. Any app can let people sign in with their HdSpace account (password or Google), the same way as "Login with Google".
This server
| Issuer | https://account.hdspace.app/o |
|---|---|
| Discovery | https://account.hdspace.app/o/.well-known/openid-configuration |
| Public keys | https://account.hdspace.app/o/.well-known/jwks.json |
| Flow | Authorization code with PKCE (S256), tokens signed with RS256 |
| Scopes | openid (required), profile, email |
1. Get a client id
Clients are created by the HdSpace administrator. Send the app name and its callback addresses, for example
https://my-app.example.com/api/auth/callback/hdspace (and
http://localhost:3000/api/auth/callback/hdspace for development). You receive a
client id, and a client secret for apps with a server. Apps without a
server (single page, mobile) are public clients: PKCE, no secret.
2. Add the provider
Any OpenID Connect library works with the discovery address. With Auth.js (Next.js):
// auth.ts
import NextAuth from "next-auth";
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [{
id: "hdspace",
name: "HdSpace",
type: "oidc",
issuer: "https://account.hdspace.app/o",
clientId: process.env.AUTH_HDSPACE_ID,
clientSecret: process.env.AUTH_HDSPACE_SECRET,
checks: ["pkce", "state", "nonce"],
authorization: { params: { scope: "openid profile email" } },
}],
});
// app/api/auth/[...nextauth]/route.ts
import { handlers } from "@/auth";
export const { GET, POST } = handlers;
// a button
<button onClick={() => signIn("hdspace")}>Login with HdSpace</button>
3. Who signed in
| Claim | Scope | Value |
|---|---|---|
sub | openid | Account id (UUID). Never changes: use it as the key of the person in your app. |
preferred_username, name, picture | profile | Username, display name, picture address (may be empty) |
email, email_verified | Email address, and whether HdSpace checked it |
Checking an ID token yourself: signature with the public keys (RS256), iss = the issuer above,
aud = your client id, exp, and the nonce you sent.
Email: trust email only when email_verified is true.
An unverified address was typed at registration and nobody proved they own it: never link it to an
existing account of your app, never use it to grant access. Key people by sub, not by email.
Keys change
Tokens name their key in the kid header. Read the keys from the JWKS address (cache them for
an hour at most), pick the one with the token's kid, and fetch the JWKS again when a
kid is unknown. Never copy a key into your code: when HdSpace changes its key, the new one
appears in the JWKS first and the old one stays there until its tokens have expired.
Security rules of this server
- Authorization code + PKCE
S256only: no implicit flow, no password grant, noplainPKCE. - Redirect addresses must match exactly; production clients use
httpsonly. - Access tokens go in the
Authorizationheader, never in a URL. - Refresh tokens rotate: use each one once. A refresh token used twice ends the whole session (theft protection).
- The authorization response carries
iss(RFC 9207): check it equals the issuer above.
4. Which account
Someone already signed in to HdSpace comes straight back as that account. Two optional parameters of the authorize URL change that:
| Parameter | Effect |
|---|---|
prompt=select_account | HdSpace shows who is signed in, with "Use another account" |
login_hint=<username or email> | The account you expect: straight back if it is the one signed in, the chooser if another one is, the login form filled in if nobody is |
"Manage your HdSpace account" link
Link to https://account.hdspace.app/account/?login_hint=<sub>&client_id=<your client id>
(the sub of the person using your app; an email or username also works and pre-fills the login
form). If this browser is signed in to HdSpace with another account, the page says so and offers to switch,
so the person never changes the wrong account.
Deleted accounts
Two kinds of deletion. In your app: your own "delete my account" button removes what your app
keeps for that sub, then calls https://account.hdspace.app/o/revoke_token/ with your refresh token; the
HdSpace account stays. On HdSpace: the person deletes their HdSpace account; it is deleted
7 days later unless they cancel, and every app removes its data when it finds out.
Your server finds out with its client id and secret (HTTP Basic, confidential clients):
GET https://account.hdspace.app/api/v1/accounts/<sub>/status
200 {"status": "active"} signed out only: keep the data
200 {"status": "disabled"} suspended: keep the data
200 {"status": "pending_deletion"} deletion requested, may be cancelled: keep the data
410 {"status": "deleted"} gone for good: delete everything you keep for this sub
404 {"status": "unknown"} never existed here: keep the data
POST https://account.hdspace.app/api/v1/accounts/status {"subs": ["...", ...]} up to 100 at once
200 {"accounts": [{"sub": "...", "status": "..."}, ...]}
- When a refresh with HdSpace fails (
invalid_grant), ask for the status of thatsub; delete the person's data only ondeleted(HTTP 410). Anything else, or no answer: just sign them out. - People who deleted their account rarely come back: once a week, send your
subs in batches of 100 and delete the ones that aredeleted. HdSpace remembers deleted accounts for 2 years. - The entitlements answer also carries
account_status.
Sign out
Signing out of your app ends your own session only. To sign out of HdSpace too (every app on this browser),
send the person to https://account.hdspace.app/o/logout/ with id_token_hint,
client_id and a registered post_logout_redirect_uri.