Skip to content

Conversation

reivilibre
Copy link
Contributor

This PR defines a token format for PATs and implements the base storage functionality for PATs and 'Personal Sessions' which are conceptually the parent containers of PATs.

Personal Sessions survive across regenerations of PATs and are the entities associated with the device ID. In virtually every way they are functionally the same as Compat or OAuth2 Sessions.

Future work that will follow soon after this PR:

  • admin API
  • support PATs in token introspection
  • store activity tracking rows for PATs
  • ability to regenerate PATs

Part of: #4492

@reivilibre reivilibre requested a review from sandhose October 6, 2025 17:01

TokenType::PersonalAccessToken => {
// TODO
return Err(RouteError::UnknownToken(TokenType::PersonalAccessToken));
Copy link
Member

Choose a reason for hiding this comment

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

A few things I have in mind: this needs to check that both the actor and the owner are still active.

Deactivating (not locking) users should revoke all their tokens

Validating those tokens should also be done for requests to the GraphQL endpoint (optional maybe, we want to deprecate 'admin' access to the GraphQL API) and for the admin API access

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted down. Given our plans with GraphQL I'm tempted to say that we just don't accept PATs there; cuts off one more opportunity for people to get locked into a deprecated API.

Copy link

cloudflare-workers-and-pages bot commented Oct 7, 2025

Deploying matrix-authentication-service-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 277e8e8
Status: ✅  Deploy successful!
Preview URL: https://374be286.matrix-authentication-service-docs.pages.dev
Branch Preview URL: https://rei-pat-1.matrix-authentication-service-docs.pages.dev

View logs

@reivilibre reivilibre force-pushed the rei/pat_1 branch 2 times, most recently from 0783870 to 9dffe4f Compare October 7, 2025 18:42
@reivilibre reivilibre marked this pull request as ready for review October 7, 2025 19:22
@reivilibre reivilibre requested a review from sandhose October 8, 2025 09:58
Copy link
Member

@sandhose sandhose left a comment

Choose a reason for hiding this comment

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

just a nitpick over the add repository function but other than that LGTM!

pub state: SessionState,
pub owner: PersonalSessionOwner,
pub actor_user_id: Ulid,
pub human_name: String,
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if this should be optional… but I guess most tools force you to have a name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was my thought really; other tools make you put in a name and it seems self-sabotaging to not have a label for your PATs, so it seems like a good idea to just have one for simplicity.

pub id: Ulid,
pub state: SessionState,
pub owner: PersonalSessionOwner,
pub actor_user_id: Ulid,
Copy link
Member

Choose a reason for hiding this comment

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

I'm now thinking that potentially you could have no actor (like you don't need one when talking to the MAS admin API) but then the main reason for you to use PATs (and not just the client credentials grant) is if you need to access Synapse and MAS, so probably not worth supporting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also thought the same really. Seems like extra kerfuffle for no apparent benefit; could be relaxed later if it turns out to be useful though

@reivilibre reivilibre enabled auto-merge October 9, 2025 12:01
@reivilibre reivilibre merged commit 477385f into main Oct 9, 2025
20 checks passed
@reivilibre reivilibre deleted the rei/pat_1 branch October 9, 2025 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants