Save all tokens to the session

Created on 3 October 2024, 7 months ago

Problem/Motivation

Currently, in OpenIdConnect::completeAuthorization() only the 'id_token' and 'access_token' values are saved to the session, even though we also have an 'expire' and 'refresh_token' value. So all of this information is lost unless you do something with it in your own hook_openid_connect_post_authorize().

Let's fix that by saving this information to the session.

Steps to reproduce

Try to retrieve refresh token or token expiry and see that you can't.

Proposed resolution

Apply same logic as used for other tokens.

Remaining tasks

N/A

User interface changes

N/A

API changes

New methods to set and retrieve refresh token and expiry.

Data model changes

N/A

โœจ Feature request
Status

Active

Version

3.0

Component

Code

Created by

๐Ÿ‡ง๐Ÿ‡ชBelgium kristiaanvandeneynde Antwerp, Belgium

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @kristiaanvandeneynde
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium kristiaanvandeneynde Antwerp, Belgium

    kristiaanvandeneynde โ†’ changed the visibility of the branch 3.x to hidden.

  • Pipeline finished with Success
    7 months ago
    Total: 179s
    #299861
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium kristiaanvandeneynde Antwerp, Belgium
  • Status changed to RTBC 4 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium filsterjisah

    MR looks greats! Lets merge this?

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium filsterjisah

    To refresh the token, it is essential to have access to the OpenID client used to obtain the initial tokens, as it must also be utilized for refreshing them. I would suggest also storing the client id in the OpenID Connect session.

    e.g. https://git.drupalcode.org/project/openid_connect/-/merge_requests/131/d...

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium kristiaanvandeneynde Antwerp, Belgium

    Not sure I can follow. We're using the MR from this issue on a project and it's working fine in its current state. We simply always use the same client throughout our application. Also it seems like your MR is tagged against a different issue so perhaps we should keep this issue and its MR small in size? It's far easier to review and commit smaller MRs than big ones with multiple goals.

    Will set to NR but feel free to RTBC again if you agree.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium filsterjisah

    I agree with keeping MRs small in size. The point I want to emphasize is that the OpenID Connect session needs client context: in theory, you can have multiple clients active & connecting to the same Drupal accountโ€”for example, when using combinations of social clients like Facebook and Google.

    To implement anything generic inside the OpenID Connect module with these stored tokens, we need the context of their origin. Thatโ€™s the main reason I suggested including that addition in this issue. That said, I agree that this context isnโ€™t really needed when using only one client and working with code within a custom module.

    Iโ€™d love to hear your opinion on this.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium kristiaanvandeneynde Antwerp, Belgium

    I'd say there's a good chance there are many websites out there that only use one provider. For them, this MR is sufficient.

    Delaying it to add more info that then needs tests to see how well it behaves when using multiple clients alongside each other seems unnecessary. I'd rather we focus this issue on expanding what can go into a session and then another issue on investigating how well the session currently behaves with multiple clients and if we can or even need to store the client ID in said session.

    The issue is about "Save all tokens", so let's keep it like that? A Client ID is not a token, even though I understand why you brought it up.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium filsterjisah

    Alright, I'll keep the 'client ID' session addition request in the other issue so that this one can be merged.

  • First commit to issue fork.
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States pfrilling Minster, OH

    I added unit tests to the new methods and I renamed two of the methods to match the other save/retrieve token patterns:

    - retrieveTokenExpire was renamed to retrieveExpireToken
    - saveTokenExpire was renamed to saveExpireToken

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States r.aubin
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States pfrilling Minster, OH

    I rebased the code with the 3.x version to get the tests validating Drupal 10 and 11. If all tests pass, I'll get this merged.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States pfrilling Minster, OH

    All tests passed after the rebase. I went ahead and merged this.

    Thanks everyone!

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States pfrilling Minster, OH
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024