fix(auth): separate Pireon clients for authorization code and password

Pireon OAuth clients allow a single grant type. With one PIREON_CLIENT_ID of
type password, email + password worked but "Sign in with Pireon" failed with
`unauthorized_client`.

- PIREON_CLIENT_ID/SECRET: authorization_code client (Sign in with Pireon,
  Swagger UI). New PIREON_PASSWORD_CLIENT_ID/SECRET: password client, falling
  back to the former so existing setups keep working.
- Refresh tries both clients: a refresh token only works with its issuer.
- PIREON_PASSWORD_GRANT=false now also rejects password grants in the API
  (before it only hid the form).
- /api/auth/config returns clientId: null when there is no authorization_code
  client, and the web hides "Sign in with Pireon".
- docker-compose passes the new variables; docs 05/07, .env.example,
  openapi.json; unit tests for the client selection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-03 15:41:50 +02:00
parent 7532938b4e
commit cbaad17fc7
18 changed files with 321 additions and 44 deletions

View File

@@ -148,7 +148,7 @@ export const AuthStore = signalStore(
redirectToPireon$: events.on(authPageEvents.signInWithPireon).pipe(
exhaustMap(({ payload }) => {
const config = store.config();
if (!config)
if (!config?.clientId)
return [
authApiEvents.signInFailed(
'Pireon sign-in is not configured on the API',

View File

@@ -16,7 +16,8 @@ export interface CurrentUser {
/** How the browser can sign in (null config = the API has no Pireon client yet). */
export interface AuthConfig {
authorizeUrl: string;
clientId: string;
/** Null when only email + password is configured (no "Sign in with Pireon"). */
clientId: string | null;
scopes: string[];
passwordGrant: boolean;
}

View File

@@ -21,6 +21,8 @@ export class BrowserAuthorizationFlow extends AuthorizationFlow {
private readonly document = inject(DOCUMENT);
async start(config: AuthConfig, returnUrl: string): Promise<void> {
if (!config.clientId)
throw new Error('Pireon sign-in is not configured on the API');
const codeVerifier = randomString(64);
const state = randomString(32);
sessionStorage.setItem(

View File

@@ -163,7 +163,7 @@ const SAMPLE_FEED = [
/>
}
@if (auth.config(); as config) {
@if (auth.config()?.clientId) {
<pi-action-button
size="w100"
color="primary"
@@ -172,7 +172,7 @@ const SAMPLE_FEED = [
[disabled]="busy()"
(execute)="auth.signInWithPireon(returnUrl())"
/>
@if (config.passwordGrant) {
@if (passwordEnabled()) {
<pi-divider color="grey" label="o" gap="m" />
}
}