HdSpace Account

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

Issuerhttps://account.hdspace.app/o
Discoveryhttps://account.hdspace.app/o/.well-known/openid-configuration
Public keyshttps://account.hdspace.app/o/.well-known/jwks.json
FlowAuthorization code with PKCE (S256), tokens signed with RS256
Scopesopenid (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

ClaimScopeValue
subopenidAccount id (UUID). Never changes: use it as the key of the person in your app.
preferred_username, name, pictureprofileUsername, display name, picture address (may be empty)
email, email_verifiedemailEmail 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

4. Which account

Someone already signed in to HdSpace comes straight back as that account. Two optional parameters of the authorize URL change that:

ParameterEffect
prompt=select_accountHdSpace 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": "..."}, ...]}
  1. When a refresh with HdSpace fails (invalid_grant), ask for the status of that sub; delete the person's data only on deleted (HTTP 410). Anything else, or no answer: just sign them out.
  2. People who deleted their account rarely come back: once a week, send your subs in batches of 100 and delete the ones that are deleted. HdSpace remembers deleted accounts for 2 years.
  3. 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.