2. **New device checks if it can use an available protocol**
2. **New device checks if it can use an available protocol**
Once the existing device has determined the server name it then undertakes steps to determine if it is able to work with the homeserver.
The existing device then undertakes steps to determine if it is able to work with the homeserver.
The steps are as follows:
The steps are as follows:
- use [Server Discovery](https://spec.matrix.org/v1.15/client-server-api/#server-discovery) to determine the `base_url` from the well-known URI
- checks that the homeserver has the OAuth 2.0 API available by [`GET /_matrix/client/v1/auth_metadata`](https://spec.matrix.org/v1.15/client-server-api/#server-metadata-discovery) on the homeserver [base URL]
- checks that the homeserver has the OAuth 2.0 API available by [`GET /_matrix/client/v1/auth_metadata`](https://spec.matrix.org/v1.15/client-server-api/#server-metadata-discovery)
*New device => Homeserver via HTTP*
*New device => Homeserver via HTTP*
@ -956,22 +955,21 @@ sequenceDiagram
rect rgba(255,0,0, 0.1)
rect rgba(255,0,0, 0.1)
#alt if New device scanned QR code
#alt if New device scanned QR code
note over N: New device completes checks from secure channel establishment step 6 - it now trusts the channel
note over N: New device completes checks from secure channel establishment step 6 - it now trusts the channel
note over N: 1) New device got server name from the QR code
note over N: 1) New device got server base URL from the QR code
#else if Existing device scanned QR code
#else if Existing device scanned QR code
# note over E: Existing device completes step 6
# note over E: Existing device completes step 6
# note over E: Existing device displays checkmark and CheckCode
# note over E: Existing device displays checkmark and CheckCode
# note over E: 1) Existing device sends m.login.protocols message
# note over E: 1) Existing device sends m.login.protocols message
|`protocols`|required `string[]`|Array of: one of: `device_authorization_grant` |
|`protocols`|required `string[]`|Array of: one of: `device_authorization_grant` |
|`homeserver`|required `string`|The [server name](https://spec.matrix.org/v1.15/appendices/#server-name) of the Matrix homeserver|
|`base_url`|required `string`|The [base URL] of the Matrix homeserver for client-server connections|
```json
```json
{
{
"type": "m.login.protocols",
"type": "m.login.protocols",
"protocols": ["device_authorization_grant"],
"protocols": ["device_authorization_grant"],
"homeserver": "matrix.org"
"base_url": "https://matrix-client.matrix.org"
}
}
```
```
@ -1426,7 +1423,7 @@ Fields:
|--- |--- |--- |
|--- |--- |--- |
|`type`|required `string`|`m.login.failure`|
|`type`|required `string`|`m.login.failure`|
|`reason`|required `string`| One of: <table><tr><td><strong>Value</strong></td><td><strong>Description</strong></td></tr><tr><td><code>authorization_expired</code></td><td>The Device Authorization Grant expired</td></tr><tr><td><code>device_already_exists</code></td><td>The device ID specified by the new client already exists in the Homeserver provided device list</td></tr><tr><td><code>device_not_found</code></td><td>The new device is not present in the device list as returned by the Homeserver</td></tr><tr><td><code>unexpected_message_received</code></td><td>Sent by either device to indicate that they received a message of a type that they weren't expecting</td></tr><tr><td><code>unsupported_protocol</code></td><td>Sent by a device where no suitable protocol is available or the requested protocol requested is not supported</td></tr><tr><td><code>user_cancelled</code></td><td>Sent by either new or existing device to indicate that the user has cancelled the login</td></tr></table>|
|`reason`|required `string`| One of: <table><tr><td><strong>Value</strong></td><td><strong>Description</strong></td></tr><tr><td><code>authorization_expired</code></td><td>The Device Authorization Grant expired</td></tr><tr><td><code>device_already_exists</code></td><td>The device ID specified by the new client already exists in the Homeserver provided device list</td></tr><tr><td><code>device_not_found</code></td><td>The new device is not present in the device list as returned by the Homeserver</td></tr><tr><td><code>unexpected_message_received</code></td><td>Sent by either device to indicate that they received a message of a type that they weren't expecting</td></tr><tr><td><code>unsupported_protocol</code></td><td>Sent by a device where no suitable protocol is available or the requested protocol requested is not supported</td></tr><tr><td><code>user_cancelled</code></td><td>Sent by either new or existing device to indicate that the user has cancelled the login</td></tr></table>|
|`homeserver`|`string`| When the existing device is sending this it can include the [server name](https://spec.matrix.org/v1.15/appendices/#server-name) of the Matrix homeserver so that the new device can at least save the user the hassle of typing it in|
|`homeserver`|`string`| When the existing device is sending this it can include the [server name] of the Matrix homeserver so that the new device can at least save the user the hassle of typing it in|
Example:
Example:
@ -1749,3 +1746,5 @@ The unstable value of `IO_ELEMENT_MSC4108_CONCURRENT_WRITE` should be used inste
This MSC builds on [MSC4341] which proposes support for RFC 8628 Device Authorization Grant in Matrix.
This MSC builds on [MSC4341] which proposes support for RFC 8628 Device Authorization Grant in Matrix.
[MSC4341]: https://github.com/matrix-org/matrix-spec-proposals/pull/4341 "MSC4341 Support for RFC 8628 Device Authorization Grant"
[MSC4341]: https://github.com/matrix-org/matrix-spec-proposals/pull/4341 "MSC4341 Support for RFC 8628 Device Authorization Grant"