Skip to content
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

MSC2964: Usage of OAuth 2.0 authorization code grant and refresh token grant #2964

Open
wants to merge 32 commits into
base: main
Choose a base branch
from

Conversation

sandhose
Copy link
Member

@sandhose sandhose commented Jan 14, 2021

Rendered

Related: matrix-org/matrix-spec#636

Status:

  • Spec is feature complete
  • Reviewed for consistency with MSC3861
  • Implementations believed to be complete enough

Part of the following proposal:

Implementations:

Homeservers

Clients

In OIDC-native mode:

@turt2live turt2live changed the title MSC2964: [WIP] Matrix profile for OAuth 2.0 [WIP] MSC2964: Matrix profile for OAuth 2.0 Jan 14, 2021
@turt2live turt2live marked this pull request as draft January 14, 2021 17:27
@turt2live turt2live added kind:feature MSC for not-core and not-maintenance stuff proposal A matrix spec change proposal labels Jan 14, 2021
@sandhose
Copy link
Member Author

Related issue: matrix-org/matrix-spec#636

Related MSCs: #2965, #2966, #2967


In this MSC, there are a few areas that still need work.

First, it outlines different profiles of clients. One important client type that is not yet covered by it are CLI tools.
The natural fit for this would be the client credential grant, taking form of either a client_secret or a secret key for JWT signing.
The problem with this is that it authenticates as "the client", not a user. How users should delegate authorization to other clients is a bit unclear. Maybe RFC 8693 helps with that.

Second, there are the parts that we enforce.
For example, I chose to enforce PKCE for public clients. Since most of Matrix clients are public, I think it makes sense to enforce the current best practices here.
Another example would be credentials for confidential clients. Right now nothing is specified, but it might make sense to encourage the usage of keypairs instead of client secrets. If we encourage that, should it be enforced?
Last example, in the part about the request to the authz endpoint, I mention that the state parameter should be unpredictable. Some profiles go further than that to enforce a minimum entropy for this parameter.

Third there is device handling in general. MSC2967 talks a bit about this, but there will definitely be some changes to the device API.
An example of this is that we might want to surface client metadata when querying the devices instead of just an arbitrary name.
Another open question is should a device be deleted on logout? If so, how do we handle device that are used by multiple clients (which is technically possible with the solution proposed in #2967)?

@turt2live turt2live added the needs-implementation This MSC does not have a qualifying implementation for the SCT to review. The MSC cannot enter FCP. label Jun 8, 2021
Comment on lines 149 to 152
Whenever the client ask for a token (either with a refresh token or by initiating a authorization code flow) the authentication server returns the list of scopes for which the token is valid.
This helps client track what scopes they currently have access to, and let them upgrade temporarily a token with additional scopes to perform privileged actions.
The authorization server can also downgrade the scopes of a session after a certain time by returning a reduced list of scopes when refreshing the token.
The scope definitions are out of scope of this MSC and are defined in [MSC2967](/~https://github.com/matrix-org/matrix-doc/pull/2967).
Copy link
Contributor

@ShadowJonathan ShadowJonathan May 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this be replaced with; the client requesting for a seperate token with only the required scope to perform this action, only for it to be dropped (deactivated) immidiately after?

Something about upgrading the same token doesn't sit well with me from a security perspective, it might be a deliberately locked-down token, and/or multiple actions at once could race to upgrade/downgrade the current token.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a separate token purely for one scope / set of scopes sounds like a really good idea, especially for race condition reasons. Races could be also avoided by introducing state on AS/OP side, but that is quite out of scope of oauth2 specification (if I'm not mistaken)

At the same time, it would make specification compatible with more possible OP implementations.

Making it single use would be easily doable using jti claim on that token.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that we no longer attempt to provide a replacement for UIA, so this thread is probably outdated too. @sandhose could you confirm?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We gave alternatives to all of the operations currently protected by UIA with a deeplink to the account management UI through MSC4191

Longterm, the idea is to:

  • define scopes for specific actions
  • define a way to step-up authentication, temporarily or not

But for the sake of simplicity, this isn't in part of the proposal

@hughns hughns changed the title [WIP] MSC2964: Matrix profile for OAuth 2.0 [WIP] MSC2964: Delegation of auth from homeserver to OIDC Provider May 25, 2022
@turt2live turt2live added the matrix-2.0 Required for Matrix 2.0 label Mar 3, 2023
@sandhose sandhose changed the title [WIP] MSC2964: Delegation of auth from homeserver to OpenID Provider [WIP] MSC2964: Usage of OAuth 2.0 authorization code grant and refresh token grant Sep 4, 2024
@sandhose sandhose changed the title [WIP] MSC2964: Usage of OAuth 2.0 authorization code grant and refresh token grant MSC2964: Usage of OAuth 2.0 authorization code grant and refresh token grant Sep 16, 2024
@sandhose sandhose marked this pull request as ready for review September 16, 2024 13:36
Copy link

@tonkku107 tonkku107 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nitpicky things things I noticed while reading through the updated version and suggested fixes

proposals/2964-oauth2-profile.md Outdated Show resolved Hide resolved
proposals/2964-oauth2-profile.md Outdated Show resolved Hide resolved

grant_type=authorization_code
&code=iuB7Eiz9heengah1joh2ioy9ahChuP6R
&redirect_uri=https://app.example.com/oauth2-callback

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
&redirect_uri=https://app.example.com/oauth2-callback
&redirect_uri=https%3A%2F%2Fapp.example.com%2Foauth2-callback

URL encoding

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, this is done for readability

Comment on lines +110 to +111
redirect_uri = https://app.example.com/oauth2-callback &
scope = urn:matrix:client:api:* urn:matrix:client:device:AAABBBCCCDDD &

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
redirect_uri = https://app.example.com/oauth2-callback &
scope = urn:matrix:client:api:* urn:matrix:client:device:AAABBBCCCDDD &
redirect_uri = https%3A%2F%2Fapp.example.com%2Foauth2-callback &
scope = urn%3Amatrix%3Aclient%3Aapi%3A*+urn%3Amatrix%3Aclient%3Adevice%3AAAABBBCCCDDD &

These values would be URL encoded

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept this part simplified with no URL-encoding and extra spaces. It might be worth saying that, and give the actual url-encoded, with no space added URL in addition

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The values are already listed above in their non-url-encoded format. The oauth specs also include line breaks in their examples but url-encode the values

sandhose and others added 2 commits September 17, 2024 15:02
Co-authored-by: Tonkku <tonkku.kallio3@gmail.com>
@sandhose sandhose force-pushed the msc/sandhose/oauth2-profile branch from e25fd17 to c57be5e Compare January 17, 2025 09:28
@turt2live turt2live added implementation-needs-checking The MSC has an implementation, but the SCT has not yet checked it. kind:core MSC which is critical to the protocol's success and removed needs-implementation This MSC does not have a qualifying implementation for the SCT to review. The MSC cannot enter FCP. kind:feature MSC for not-core and not-maintenance stuff labels Jan 18, 2025

#### Authorization request

It then constructs the authorization request URL using the `authorization_endpoint` value, with the following query parameters:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OAuth also has Pushed Authorization Requests which attempt to alleviate some of the issues of query parameters (see e.g. the introduction of RFC9126). I wonder if it'd be worth to consider these from the outset here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point, although because most Matrix clients will be public clients, we wouldn't really gain from the cryptographic integrity or confidentiality advantages PAR gives us. It would help us in two other ways though:

  • validating the authorisation request earlier, to possibly show a user-friendly error within the client
  • large authorisation requests, if we start having fine-grained authorisations

This is why for now, I'd prefer leaving them out of the proposal for the sake of simplicity, and introduce them later (probably alongside RAR) when we actually need it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense and sounds fair to me. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
implementation-needs-checking The MSC has an implementation, but the SCT has not yet checked it. kind:core MSC which is critical to the protocol's success matrix-2.0 Required for Matrix 2.0 proposal A matrix spec change proposal
Projects
Status: Proposed for FCP readiness
Development

Successfully merging this pull request may close these issues.