Use external PHP library to handle Oauth

Created on 25 September 2019, almost 6 years ago
Updated 29 July 2025, 19 days ago

It would be more sensible to use the https://github.com/thephpleague/oauth2-client library to handle Oauth within the module to reduce the amount of custom code used by the module and improve stability.

Feature request
Status

Active

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom MrDaleSmith

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇬🇧United Kingdom MrDaleSmith

    The work has been done and will soon be merged into a 4.2.x release from the PR at https://git.drupalcode.org/project/patreon/-/merge_requests/4.

    Changes

    PatreonServiceInterface

    • The getOauth() method now returns a \HansPeterOrding\OAuth2\Client\Provider\Patreon object. This is configured to handle obtaining Oauth tokens from the Patreon API and should be used instead of the previous methods. This object does not allow for a return path to be set in the API call, so if you have custom code that relies on this you will need to find an alternative method.
    • The getToken() method now automatically checks whether the League\OAuth2\Client\Token\AccessTokenInterface has expired and if so will attempt to obtain refreshed tokens from the Patreon API. It still returns the API token as a string.
    • The getScopes() and setScopes() methods have been deprecated and will be removed in future versions of the module: the Oauth client handles to setting of scopes for Oauth access, so these methods no longer have any functionality. If you require setting custom scope, you will have to create your own League Oauth Client and override the one used by the module.
    • The getRefreshToken() method has been deprecated as the refresh token is stored within the AccessTokenInterface and used automatically by the underlying code when required. If you require access to the refresh token, you will need to use the getStoredToken() method to access the current Access Token.
    • The getAuthoriseUrl() method has been deprecated and no longer returns a value. The authorisation URL is obtained from the Patreon Oauth Client returned by getOauth().
    • The decodeState() method has been deprecated as the URL the Patreon API returns users no no longer contains any encoded values. This is related to the removal of functionality around allowing the API to return a final url to redirect users to.
    • The retry() method has been deprecated and no longer carries out any functions. If you require retry handling, will will need to implement custom code to provide this.
    • The default service uses the global AuthToken by default. If you require using different token to access the API, the PatreonUserService should be used as this allows for a custom AuthToken to be set with its setToken() method.

    General changes

    • The constants set in the patreon.module and patreon_user.module have been moved into the PatreonServiceInterface and PatreonUserService respectively.
    • The code providing Token-support in the Patreon Extras module has been moved to a separate tokens.inc file as required by that module.
    • The module has been updated to only support Drupal 10 and 11 sites: this is so the code can rely on the features of PHP 8.3. Usage with lower versions is not supported, although I have not restricted this in the composer.json file.
  • 🇬🇧United Kingdom MrDaleSmith

    Can now be tested against https://www.drupal.org/project/patreon/releases/4.2.0-alpha1 so I will close this ticket.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024