|
| 1 | +# Copyright 2023 The Matrix.org Foundation C.I.C. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +swagger: '2.0' |
| 15 | +info: |
| 16 | + title: "Matrix Client-Server Registration and Login API" |
| 17 | + version: "1.0.0" |
| 18 | +host: localhost:8008 |
| 19 | +schemes: |
| 20 | + - https |
| 21 | + - http |
| 22 | +basePath: /_matrix/client/v1 |
| 23 | +consumes: |
| 24 | + - application/json |
| 25 | +produces: |
| 26 | + - application/json |
| 27 | +securityDefinitions: |
| 28 | + $ref: definitions/security.yaml |
| 29 | +paths: |
| 30 | + "/login/get_token": |
| 31 | + post: |
| 32 | + summary: Optional endpoint to generate a single-use, time-limited, `m.login.token` token. |
| 33 | + description: |- |
| 34 | + Optional endpoint - the server is not required to implement this endpoint if it does not |
| 35 | + intend to use or support this functionality. |
| 36 | +
|
| 37 | + This API endpoint uses the [User-Interactive Authentication API](/client-server-api/#user-interactive-authentication-api). |
| 38 | +
|
| 39 | + An already-authenticated client can call this endpoint to generate a single-use, time-limited, |
| 40 | + token for an unauthenticated client to log in with, becoming logged in as the same user which |
| 41 | + called this endpoint. The unauthenticated client uses the generated token in a `m.login.token` |
| 42 | + login flow with the homeserver. |
| 43 | +
|
| 44 | + Clients, both authenticated and unauthenticated, might wish to hide user interface which exposes |
| 45 | + this feature if the server is not offering it. Authenticated clients can check for support on |
| 46 | + a per-user basis with the `m.get_login_token` [capability](/client-server-api/#capabilities-negotiation), |
| 47 | + while unauthenticated clients can detect server support by looking for an `m.login.token` login |
| 48 | + flow with `get_login_token: true` on [`GET /login`](/client-server-api/#post_matrixclientv3login). |
| 49 | +
|
| 50 | + In v1.7 of the specification, transmission of the generated token to an unauthenticated client is |
| 51 | + left as an implementation detail. Future MSCs such as [MSC3906](https://github.com/matrix-org/matrix-spec-proposals/pull/3906) |
| 52 | + might standarise a way to transmit the token between clients. |
| 53 | +
|
| 54 | + The generated token MUST only be valid for a single login, enforced by the server. Clients which |
| 55 | + intend to log in multiple devices must generate a token for each. |
| 56 | +
|
| 57 | + With other User-Interactive Authentication (UIA)-supporting endpoints, servers sometimes do not re-prompt |
| 58 | + for verification if the session recently passed UIA. For this endpoint, servers should always re-prompt |
| 59 | + the user for verification to ensure explicit consent is gained for each additional client. |
| 60 | +
|
| 61 | + Servers are encouraged to apply stricter than normal rate limiting to this endpoint, such as maximum |
| 62 | + of 1 request per minute. |
| 63 | + operationId: generateLoginToken |
| 64 | + x-addedInMatrixVersion: "1.7" |
| 65 | + security: |
| 66 | + - accessToken: [] |
| 67 | + parameters: |
| 68 | + - in: body |
| 69 | + name: body |
| 70 | + required: true |
| 71 | + schema: |
| 72 | + type: object |
| 73 | + properties: |
| 74 | + auth: |
| 75 | + description: |- |
| 76 | + Additional authentication information for the user-interactive authentication API. |
| 77 | + allOf: |
| 78 | + - $ref: "definitions/auth_data.yaml" |
| 79 | + responses: |
| 80 | + 200: |
| 81 | + description: The login token an unauthenticated client can use to log in as the requesting user. |
| 82 | + examples: |
| 83 | + application/json: { |
| 84 | + "login_token": "<opaque string>", |
| 85 | + "expires_in_ms": 120000 |
| 86 | + } |
| 87 | + schema: |
| 88 | + type: object |
| 89 | + required: ["login_token", "expires_in_ms"] |
| 90 | + properties: |
| 91 | + login_token: |
| 92 | + type: string |
| 93 | + description: The login token for the `m.login.token` login flow. |
| 94 | + expires_in_ms: |
| 95 | + type: integer |
| 96 | + description: |- |
| 97 | + The time remaining in milliseconds until the homeserver will no longer accept the token. `120000` |
| 98 | + (2 minutes) is recommended as a default. |
| 99 | + 400: |
| 100 | + description: |- |
| 101 | + The request was malformed, or the user does not have an ability to generate tokens for their devices, |
| 102 | + as implied by the [User-Interactive Authentication API](/client-server-api/#user-interactive-authentication-api). |
| 103 | +
|
| 104 | + Clients should verify whether the user has an ability to call this endpoint with the `m.get_login_token` |
| 105 | + [capability](/client-server-api/#capabilities-negotiation). |
| 106 | + schema: |
| 107 | + "$ref": "definitions/errors/error.yaml" |
| 108 | + 401: |
| 109 | + description: |- |
| 110 | + The homeserver requires additional authentication information. |
| 111 | + schema: |
| 112 | + "$ref": "definitions/auth_response.yaml" |
| 113 | + 429: |
| 114 | + description: This request was rate-limited. |
| 115 | + schema: |
| 116 | + "$ref": "definitions/errors/rate_limited.yaml" |
| 117 | + tags: |
| 118 | + - Session management |
0 commit comments