mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-25 11:29:53 +01:00
feat(api): add API v1 login, setup, token, grant and password endpoints
Adds the seven auth operations to the spec (createAccessToken, listGrants, revokeGrant and logout in core; login, setupFirstAdmin and changePassword in the password module), the bearerAuth/grantAuth schemes, and vacuum rules requiring explicit security and a known x-scope. The strict handlers sit on core/apiauth and are covered end to end against a real SQLite database. The first operations with parameters make the generated code import github.com/oapi-codegen/runtime. An oapi-codegen overlay renames the shared offset/limit parameter types, since a generated Offset clashes with Ginkgo's dot-imported Offset in this package's tests; the published spec is unchanged.
This commit is contained in:
parent
4f2d350757
commit
294c1a9a6a
34 changed files with 3741 additions and 33 deletions
3
api/openapi/components/headers/WWWAuthenticate.yaml
Normal file
3
api/openapi/components/headers/WWWAuthenticate.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
description: 'RFC 6750 Bearer challenge, for example `Bearer error="insufficient_scope", scope="read"`.'
|
||||
schema:
|
||||
type: string
|
||||
5
api/openapi/components/responses/Conflict.yaml
Normal file
5
api/openapi/components/responses/Conflict.yaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
description: "The request conflicts with the server's state, for example `setup_complete` or `password_managed_externally`."
|
||||
content:
|
||||
application/problem+json:
|
||||
schema:
|
||||
$ref: ../schemas/Problem.yaml
|
||||
|
|
@ -1,4 +1,7 @@
|
|||
description: The caller is authenticated but not allowed to do this.
|
||||
headers:
|
||||
WWW-Authenticate:
|
||||
$ref: ../headers/WWWAuthenticate.yaml
|
||||
content:
|
||||
application/problem+json:
|
||||
schema:
|
||||
|
|
|
|||
5
api/openapi/components/responses/PayloadTooLarge.yaml
Normal file
5
api/openapi/components/responses/PayloadTooLarge.yaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
description: "The request body is too large (`payload_too_large`)."
|
||||
content:
|
||||
application/problem+json:
|
||||
schema:
|
||||
$ref: ../schemas/Problem.yaml
|
||||
10
api/openapi/components/responses/TooManyRequests.yaml
Normal file
10
api/openapi/components/responses/TooManyRequests.yaml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
description: "Rate limited (`rate_limited`). Retry after the `Retry-After` seconds."
|
||||
headers:
|
||||
Retry-After:
|
||||
description: Seconds to wait before retrying.
|
||||
schema:
|
||||
type: integer
|
||||
content:
|
||||
application/problem+json:
|
||||
schema:
|
||||
$ref: ../schemas/Problem.yaml
|
||||
|
|
@ -1,4 +1,7 @@
|
|||
description: Missing, invalid, or expired credentials.
|
||||
headers:
|
||||
WWW-Authenticate:
|
||||
$ref: ../headers/WWWAuthenticate.yaml
|
||||
content:
|
||||
application/problem+json:
|
||||
schema:
|
||||
|
|
|
|||
19
api/openapi/components/schemas/AccessToken.yaml
Normal file
19
api/openapi/components/schemas/AccessToken.yaml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
type: object
|
||||
description: "A short-lived access token. Opaque; clients must not decode it."
|
||||
required: [accessToken, tokenType, expiresIn, scopes]
|
||||
properties:
|
||||
accessToken:
|
||||
type: string
|
||||
description: "The token. Send it as `Authorization: Bearer <token>`."
|
||||
tokenType:
|
||||
type: string
|
||||
enum: [Bearer]
|
||||
description: "Always `Bearer`."
|
||||
expiresIn:
|
||||
type: integer
|
||||
description: Seconds until the token expires.
|
||||
scopes:
|
||||
type: array
|
||||
description: "Scopes the token actually carries, which may be fewer than requested."
|
||||
items:
|
||||
$ref: ./Scope.yaml
|
||||
19
api/openapi/components/schemas/AuthUser.yaml
Normal file
19
api/openapi/components/schemas/AuthUser.yaml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
type: object
|
||||
description: The user a grant belongs to.
|
||||
required: [id, userName, name, isAdmin, passwordChangeable]
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
description: User id.
|
||||
userName:
|
||||
type: string
|
||||
description: Login name.
|
||||
name:
|
||||
type: string
|
||||
description: Display name.
|
||||
isAdmin:
|
||||
type: boolean
|
||||
description: Whether the user is an administrator.
|
||||
passwordChangeable:
|
||||
type: boolean
|
||||
description: "Whether `POST /auth/password` can change this user's password. Clients hide \"change password\" when false."
|
||||
34
api/openapi/components/schemas/CredentialsRequest.yaml
Normal file
34
api/openapi/components/schemas/CredentialsRequest.yaml
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
type: object
|
||||
description: "Username, password and client description for a login or first-admin setup."
|
||||
required: [username, password, client]
|
||||
properties:
|
||||
username:
|
||||
type: string
|
||||
minLength: 1
|
||||
maxLength: 255
|
||||
description: Login name.
|
||||
password:
|
||||
type: string
|
||||
minLength: 1
|
||||
maxLength: 1024
|
||||
description: Password.
|
||||
client:
|
||||
type: string
|
||||
minLength: 1
|
||||
maxLength: 64
|
||||
description: Name of the client app.
|
||||
clientVersion:
|
||||
type: string
|
||||
maxLength: 32
|
||||
description: Version of the client app.
|
||||
name:
|
||||
type: string
|
||||
minLength: 1
|
||||
maxLength: 64
|
||||
description: "Label for this grant. Defaults to `client`."
|
||||
scopes:
|
||||
type: array
|
||||
maxItems: 32
|
||||
description: "Scopes the grant may hold. Omit for `all`."
|
||||
items:
|
||||
$ref: ./ScopeRequest.yaml
|
||||
41
api/openapi/components/schemas/Grant.yaml
Normal file
41
api/openapi/components/schemas/Grant.yaml
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
type: object
|
||||
description: A long-lived grant held by one client of one user.
|
||||
required: [id, name, client, clientVersion, scopes, provider, createdAt, lastUsedAt, lastUsedIp, current]
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
description: Grant id.
|
||||
name:
|
||||
type: string
|
||||
description: Label shown to the user.
|
||||
client:
|
||||
type: string
|
||||
description: Name of the client app that holds the grant.
|
||||
clientVersion:
|
||||
type: string
|
||||
nullable: true
|
||||
description: "Version of the client app, when it sent one."
|
||||
scopes:
|
||||
type: array
|
||||
description: Scopes this grant may mint tokens for.
|
||||
items:
|
||||
$ref: ./Scope.yaml
|
||||
provider:
|
||||
type: string
|
||||
description: "How the grant was created, for example `password` or `setup`. Free-form; new values may appear."
|
||||
createdAt:
|
||||
type: string
|
||||
format: date-time
|
||||
description: When the grant was created.
|
||||
lastUsedAt:
|
||||
type: string
|
||||
format: date-time
|
||||
nullable: true
|
||||
description: "When the grant was last used, at a coarse granularity. Null until first use."
|
||||
lastUsedIp:
|
||||
type: string
|
||||
nullable: true
|
||||
description: Client IP of the last use. Null until first use.
|
||||
current:
|
||||
type: boolean
|
||||
description: True for the grant that made this request.
|
||||
16
api/openapi/components/schemas/GrantCreated.yaml
Normal file
16
api/openapi/components/schemas/GrantCreated.yaml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
type: object
|
||||
description: "Returned by every login method. The secret is shown only here; store it and never parse it."
|
||||
required: [secret, grant, user]
|
||||
properties:
|
||||
secret:
|
||||
type: string
|
||||
maxLength: 512
|
||||
description: "Opaque grant secret. Send it as a Bearer credential to `POST /auth/token`."
|
||||
grant:
|
||||
description: The new grant.
|
||||
allOf:
|
||||
- $ref: ./Grant.yaml
|
||||
user:
|
||||
description: The user the grant belongs to.
|
||||
allOf:
|
||||
- $ref: ./AuthUser.yaml
|
||||
18
api/openapi/components/schemas/GrantList.yaml
Normal file
18
api/openapi/components/schemas/GrantList.yaml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
type: object
|
||||
description: "A page of the caller's grants."
|
||||
required: [items, total, offset, limit]
|
||||
properties:
|
||||
items:
|
||||
type: array
|
||||
description: "Grants on this page, by last use, most recent first; never-used grants last."
|
||||
items:
|
||||
$ref: ./Grant.yaml
|
||||
total:
|
||||
type: integer
|
||||
description: Total number of grants.
|
||||
offset:
|
||||
type: integer
|
||||
description: Zero-based index of the first returned item.
|
||||
limit:
|
||||
type: integer
|
||||
description: Maximum number of items in this page.
|
||||
8
api/openapi/components/schemas/LogoutResponse.yaml
Normal file
8
api/openapi/components/schemas/LogoutResponse.yaml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
type: object
|
||||
description: Result of a logout.
|
||||
required: [logoutUrl]
|
||||
properties:
|
||||
logoutUrl:
|
||||
type: string
|
||||
nullable: true
|
||||
description: "Where to send the browser to finish logging out of an external provider. Null when there is nothing more to do."
|
||||
18
api/openapi/components/schemas/PasswordChangeRequest.yaml
Normal file
18
api/openapi/components/schemas/PasswordChangeRequest.yaml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
type: object
|
||||
description: "Change the caller's own password."
|
||||
required: [currentPassword, newPassword]
|
||||
properties:
|
||||
currentPassword:
|
||||
type: string
|
||||
minLength: 1
|
||||
maxLength: 1024
|
||||
description: The current password.
|
||||
newPassword:
|
||||
type: string
|
||||
minLength: 1
|
||||
maxLength: 1024
|
||||
description: The new password.
|
||||
revokeOtherGrants:
|
||||
type: boolean
|
||||
default: true
|
||||
description: "Revoke every other grant of the user. The calling grant always survives. Default true."
|
||||
|
|
@ -16,7 +16,7 @@ properties:
|
|||
description: HTTP status code of this response.
|
||||
detail:
|
||||
type: string
|
||||
description: Human-readable explanation specific to this occurrence. Omitted for internal errors.
|
||||
description: Human-readable explanation specific to this occurrence. Omitted unless the server marked the text as safe to show clients.
|
||||
code:
|
||||
type: string
|
||||
description: Machine-readable error code, and the value clients switch on. New codes may be added.
|
||||
|
|
|
|||
5
api/openapi/components/schemas/Scope.yaml
Normal file
5
api/openapi/components/schemas/Scope.yaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
type: string
|
||||
description: |
|
||||
A permission scope. Scopes mirror capability modules; `x:write` includes `x`. `all` appears only on
|
||||
grants and means every scope the user is entitled to, now and in future releases. New scopes may be added.
|
||||
enum: [all, read, password]
|
||||
4
api/openapi/components/schemas/ScopeRequest.yaml
Normal file
4
api/openapi/components/schemas/ScopeRequest.yaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
type: string
|
||||
description: "A requested scope. Scopes the server does not know are dropped, not rejected, so newer clients keep working."
|
||||
pattern: '^[a-z][a-z-]*(:write)?$'
|
||||
maxLength: 64
|
||||
9
api/openapi/components/schemas/TokenRequest.yaml
Normal file
9
api/openapi/components/schemas/TokenRequest.yaml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
type: object
|
||||
description: Optional narrowing of a new access token.
|
||||
properties:
|
||||
scopes:
|
||||
type: array
|
||||
maxItems: 32
|
||||
description: "Subset of the grant's scopes. Omit for all of them; an empty list asks for none."
|
||||
items:
|
||||
$ref: ./ScopeRequest.yaml
|
||||
Loading…
Add table
Add a link
Reference in a new issue