Skip to content

MSC2965: OAuth 2.0 Authorization Server Metadata discovery #2965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Mar 29, 2025
Merged
Changes from 6 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
ef474ee
OIDC discovery MSC
sandhose Jan 14, 2021
4d9345c
Add `account` field
hughns May 2, 2022
4a24cf6
Add id_token_hint to account management URL
hughns May 6, 2022
f5b54bf
Add reference to MSC3861
hughns Aug 5, 2022
1cc4976
Add missing heading
hughns Sep 22, 2022
6455b1f
Fix reference to MSC3861
hughns Feb 8, 2023
2a242bb
Update proposals/2965-oidc-discovery.md
hughns Aug 21, 2023
ae920ad
Fix typo
hughns Aug 21, 2023
d9d56f3
Update 2965-oidc-discovery.md
hughns Aug 21, 2023
74b29e0
Update proposals/2965-oidc-discovery.md
hughns Aug 21, 2023
610c22c
Update proposals/2965-oidc-discovery.md
hughns Aug 21, 2023
eed9e60
OIDC Provider -> OpenID Provider
hughns Aug 21, 2023
fdcde60
Define account management URL params
hughns Aug 21, 2023
c0b2565
Link for account management URLs
hughns Aug 21, 2023
e9e3ee1
MSC2965: move from well-known discovery to a dedicated C-S endpoint
sandhose Nov 29, 2023
a36c44a
MSC2965: add a note about why the well-known alternative has been dis…
sandhose Nov 30, 2023
7642a60
MSC2965: move the account management URL to the provider metadata
sandhose Dec 5, 2023
a0218df
MSC2965: line breaks
sandhose Dec 5, 2023
e852963
MSC2965: update note about the account endpoint metadata
sandhose Dec 5, 2023
1bb6dde
Move the /auth_issuer endpoint to the v1 prefix
sandhose Feb 21, 2024
e70cd3d
Add the `org.matrix.cross_signing_reset` action
sandhose Feb 21, 2024
754b290
Typo
sandhose Feb 21, 2024
56949de
Merge branch 'matrix-org:main' into msc/sandhose/oidc-discovery
sandhose Sep 3, 2024
45e9063
Rename MSC
sandhose Sep 4, 2024
27bb308
Remove account-related URLs
sandhose Sep 4, 2024
acabca8
Mention RFC8414 as alternative
sandhose Sep 4, 2024
61fc092
Outline another alternative: publish the metadata through a C-S API
sandhose Jan 17, 2025
331ac79
Fix the alternative flow
sandhose Jan 17, 2025
76dfb12
Publish the auth server metadata through a new C-S API endpoint
sandhose Jan 17, 2025
abd969a
renamed 2965-oidc-discovery.md -> 2965-auth-metadata.md
sandhose Jan 17, 2025
0e7cea0
Clarify auth & rate limiting requirements
sandhose Jan 22, 2025
2aed234
Mention the MSCs using each metadata value
sandhose Jan 22, 2025
93d1b09
Explain what to do when next-gen auth is not available
sandhose Jan 22, 2025
ee1c23d
Add rationale for not using a .well-known endpoint
sandhose Jan 22, 2025
885a50f
Reformat with prettier
sandhose Jan 22, 2025
acd7042
Add `issuer` to the required metadata fields
sandhose Mar 5, 2025
8719e6f
Explain why we don't just use static C-S endpoints
sandhose Mar 5, 2025
27f374e
Apply suggestions from code review
sandhose Mar 5, 2025
c313791
Move the rationale for not using a `.well-known` document to the alte…
sandhose Mar 5, 2025
95a764f
Typo
sandhose Mar 5, 2025
900c94c
Clarify why using the .well-known would be confusing
sandhose Mar 18, 2025
706f0bb
Clarify what 'UIA flows' are exactly
sandhose Mar 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions proposals/2965-oidc-discovery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# MSC2965: OIDC Provider discovery

This proposal is part of the broader [MSC3861: Matrix architecture change to delegate authentication via OIDC](https://github.com/matrix-org/matrix-spec-proposals/pull/3861).

To be able to initiate an OAuth 2.0 login flow to use a Matrix server, the client needs to know the location of the authentication server in use.

## Proposal

Clients already discover the homeserver when doing a server discovery via the well-known document.

Two new fields are added to this document to support OIDC Provider discovery:

- REQUIRED `issuer` - the OIDC Provider that is trusted by the homeserver
- OPTIONAL `account` - the URL where the user is able to access the account management capabilities of the OIDC Provider

For example:

```
GET /.well-known/matrix/client
Host: example.com
Accept: application/json
```

```
HTTP/1.1 200 OK
Content-Type: application/json
```

```json
{
"m.homeserver": {
"base_url": "https://matrix-client.example.com"
},
"m.identity_server": {
"base_url": "https://identity.example.com"
},
"m.authentication": {
"issuer": "https://account.example.com",
"account": "https://account.example.com/myaccount"
}
}
```

The authentication server metadata can then be discovered by the client using [OpenID Connect Discovery 1.0](https://openid.net/specs/openid-connect-discovery-1_0.html) against the `issuer` field.

```
GET /.well-known/openid-configuration
Host: account.example.com
Accept: application/json
```

```
HTTP/1.1 200 OK
Content-Type: application/json
```

```json
{
"issuer": "https://account.example.com/",
"authorization_endpoint": "https://account.example.com/oauth2/auth",
"token_endpoint": "https://account.example.com/oauth2/token",
"registration_endpoint": "https://account.example.com/oauth2/clients/register",
"end_session_edntpoint": "https://account.example.com/oauth2/logout",
"jwks_uri": "https://account.example.com/.well-known/jwks.json",
"response_types_supported": ["code"],
"grant_types_sypported": ["authorization_code", "refresh_token"],
"response_mode_sypported": ["query", "fragment"],
"//": "some fields omitted"
}
```

The account management URL may accept the following additional query parameters:

- RECOMMENDED `id_token_hint` - ID Token (as previously issued by the issuer to the client) as a hint about the current authenticated user that is requesting to be able to manage their account. This may be used by the issuer to: if not logged in then used as a login hint; if already logged in, but for a different user/identity then warn the user that they are accessing account.


## Potential issues

Not all Matrix servers have the well-known client discovery mechanism setup.
Unlike the identity server, the authentication server is necessary to login against a Matrix server.
Being unable to discover the authorization server from the Matrix Client API might be an issue in some cases.

## Alternatives

The authorization server discovery could be done by other mechanisms.

### Discovery via a new client API endpoint

The Matrix Client API could have a new endpoint to discover the issuer, e.g. `/_matrix/client/r0/auth_issuer`.

### Discovery via the `m.login.oauth2` authentication method

The spec already defines a `m.login.oauth2` authentication method, but it was never implemented.
The downside of this approach is that the plan is to deprecate the old login mechanism and it does not make sense to keep it just to discover the issuer.

### Discovery via WebFinger

OIDC already has a standard way to discover OP from an identifier: WebFinger. This is already adopted by Mastodon, and might help solving logging in via 3PIDs like emails.

Sample exchange:

```
GET /.well-known/webfinger?
resource= mxid:@john:example.com &
rel= http://openid.net/specs/connect/1.0/issuer
Host: example.com
```

```json
{
"subject": "mxid:@john:matrix.org",
"links": [
{
"rel": "http://openid.net/specs/connect/1.0/issuer",
"href": "https://account.example.com"
}
]
}
```

The `mxid` scheme is a bit arbitrary here.
The parameters in the URL should be percent-encoded, this was left unencoded for clarity.

The benefits of this approach are that it is standard and decouples the authentication server from the Matrix server: different authentication servers could be used by accounts on the server.

The downsides of this approach are:

- the `.well-known` resource is dynamic, which can be harder to host/delegate & might conflict with other services like Mastodon
- this does not cover discovering the authentication server for user registration

### Account management URL

There is no standard in OIDC for the `account` field. If one was to be standardised in future then it would make sense to use that instead.

## Security considerations

None relevant.

## Unstable prefix

While this MSC is not in a released version of the specification, clients should use the `org.matrix.msc2965.authentication` field in the client well-known discovery document instead of `m.authentication`.