| 1 | package Catalyst::Plugin::OpenIDConnect::Role::Store; | ||
| 2 | |||
| 3 | 3 | ▶ | use Moose::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 3 | ▶ | use namespace::autoclean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | =head1 NAME | ||
| 7 | |||
| 8 | Catalyst::Plugin::OpenIDConnect::Role::Store - Role defining the OIDC token store interface | ||
| 9 | |||
| 10 | =head1 DESCRIPTION | ||
| 11 | |||
| 12 | This Moose role defines the interface that any OIDC store backend must implement. | ||
| 13 | All store classes (in-memory, Redis, database, etc.) must consume this role. | ||
| 14 | |||
| 15 | =head1 REQUIRED METHODS | ||
| 16 | |||
| 17 | =head2 create_authorization_code($client_id, $user_data, $scope, $redirect_uri, $nonce, $pkce) | ||
| 18 | |||
| 19 | Creates and persists an authorization code for the given parameters. | ||
| 20 | |||
| 21 | C<$user_data> must be a plain (unblessed) hashref of the user's OIDC claims, | ||
| 22 | as returned by C<get_user_claims()>. Callers are responsible for extracting | ||
| 23 | claims from the live user object before calling this method; doing so here | ||
| 24 | (rather than in the store) ensures that any application-specific user object | ||
| 25 | (DBIx::Class row, LDAP entry, etc.) is resolved while the Catalyst context | ||
| 26 | is still available, and that the store only ever handles plain serialisable data. | ||
| 27 | |||
| 28 | C<$pkce> is an optional hashref with keys C<code_challenge> and | ||
| 29 | C<code_challenge_method>. When supplied the values are stored alongside the | ||
| 30 | code so that the token endpoint can verify the RFC 7636 PKCE proof. Omit or | ||
| 31 | pass C<undef> for flows that do not use PKCE. | ||
| 32 | |||
| 33 | Returns the authorization code string. | ||
| 34 | |||
| 35 | =cut | ||
| 36 | |||
| 37 | 3 | requires 'create_authorization_code'; | |
| 38 | |||
| 39 | =head2 get_authorization_code($code) | ||
| 40 | |||
| 41 | Retrieves an authorization code by its value. Must return C<undef> if the code | ||
| 42 | does not exist or has expired. | ||
| 43 | |||
| 44 | Returns a hashref containing at minimum: C<client_id>, C<user>, C<scope>, | ||
| 45 | C<redirect_uri>, C<nonce>, C<created_at>, C<expires_at>. | ||
| 46 | |||
| 47 | =cut | ||
| 48 | |||
| 49 | 3 | requires 'get_authorization_code'; | |
| 50 | |||
| 51 | =head2 consume_authorization_code($code) | ||
| 52 | |||
| 53 | Atomically removes an authorization code and returns its data. This is the | ||
| 54 | primary method the token endpoint must use to redeem a code; it enforces | ||
| 55 | single-use semantics without a TOCTOU race condition. | ||
| 56 | |||
| 57 | Returns the code data hashref (same structure as C<get_authorization_code>) | ||
| 58 | on success, or C<undef> if the code does not exist, has already been consumed, | ||
| 59 | or has expired. | ||
| 60 | |||
| 61 | B<Important:> Callers must not call C<get_authorization_code> followed by | ||
| 62 | C<consume_authorization_code>. Use C<consume_authorization_code> alone. | ||
| 63 | |||
| 64 | =cut | ||
| 65 | |||
| 66 | 3 | requires 'consume_authorization_code'; | |
| 67 | |||
| 68 | =head2 store_refresh_token($jti, $sub, $client_id, $ttl) | ||
| 69 | |||
| 70 | Stores a refresh token identifier (JTI) with associated metadata and a TTL | ||
| 71 | (in seconds). Called at token-issuance time so that the token endpoint can | ||
| 72 | later verify the token has not been used or revoked. | ||
| 73 | |||
| 74 | =cut | ||
| 75 | |||
| 76 | 3 | requires 'store_refresh_token'; | |
| 77 | |||
| 78 | =head2 consume_refresh_token($jti) | ||
| 79 | |||
| 80 | Atomically checks that the JTI exists in the store and removes it. Returns a | ||
| 81 | hashref containing at minimum C<sub> and C<client_id> on success, or C<undef> | ||
| 82 | if the JTI is absent (token has already been used, was explicitly revoked, or | ||
| 83 | has expired). | ||
| 84 | |||
| 85 | Callers B<must> treat a C<undef> return as C<invalid_grant> and reject the | ||
| 86 | request; this is the single-use enforcement mechanism. | ||
| 87 | |||
| 88 | =cut | ||
| 89 | |||
| 90 | 3 | requires 'consume_refresh_token'; | |
| 91 | |||
| 92 | =head2 revoke_refresh_tokens_for_user($sub) | ||
| 93 | |||
| 94 | Revokes all outstanding refresh tokens for the given subject identifier across | ||
| 95 | all clients. Called at logout time to ensure that an attacker who has stolen a | ||
| 96 | refresh token cannot continue using it after the legitimate user has logged out. | ||
| 97 | |||
| 98 | =cut | ||
| 99 | |||
| 100 | 3 | requires 'revoke_refresh_tokens_for_user'; | |
| 101 | |||
| 102 | 3 | 1; | |
| 103 | |||
| 104 | =head1 AUTHOR | ||
| 105 | |||
| 106 | Tim F. Rayner | ||
| 107 | |||
| 108 | =head1 LICENSE | ||
| 109 | |||
| 110 | This library is free software; you can redistribute it and/or modify | ||
| 111 | it under the terms of The Artistic License 2.0. | ||
| 112 | |||
| 113 | =cut | ||