Skip to content

Create OAuth Client Class #12093

@herregroen

Description

@herregroen

In order to provide a secure method of connecting sites to MyYoast we want to be able to configure an OAuth Client for the purpose of retrieving access tokens.

To do so the following is required:

  • Add https://github.com/thephpleague/oauth2-client as a dependency.
  • Prefix the library as is already done for ruckusing and idiorm ( see composer.json and the config/php-scoper/ directory ).
  • Create a Yoast\WP\Free\OAuth\Client class, suggested path: src/oauth/client.php.
    This class should have static methods to do the following:
    • save_configuration( $config ): Intended for storing client ID and secret. Should store partial configs ( just the ID or just the secret, leaving other values as they are ). If the plugin is network activated these should be stored on a network level, otherwise on a site level.
    • get_configuration(): Retrieve stored configuration, same constraints as above.
    • has_configuration(): Returns true if both a client ID and secret have been stored.
    • save_access_token( $user_id, $access_token ): Should store the access token and associated user ID. Should be stored so it is easily retrievable without knowing the user ID.
    • get_access_token( $user_id = null ): Should retrieve a stored access token. If a user ID is passed it should be an access token associated with that user ID, otherwise any stores access token.
    • get_provider(): Returns a new instance of \League\OAuth2\Client\Provider\GenericProvider configured with the stored client_id and secret. For the other values:
      • redirectUri: home_url( 'yoast/oauth/callback' ). If network activated then network_home_url( 'yoast/oauth/callback' ).
      • urlAuthorize: https://yoast.com/login/oauth/authorize
      • urlAccessToken: https://yoast.com/login/oauth/token
      • urlResourceOwnerDetails: https://my.yoast.com/api/sites/current

parent #12136

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions