limoncello-php / framework

Apache License 2.0
13 stars 1 forks source link

[Passport] Ability to add custom properties to OAuth token #52

Closed neomerx closed 7 years ago

neomerx commented 7 years ago

The spec defines ability to add custom properties to OAuth token https://tools.ietf.org/html/rfc6749#section-4.1.4 https://tools.ietf.org/html/rfc6749#section-4.3.3 https://tools.ietf.org/html/rfc6749#section-4.4.3

     {
       "access_token":"2YotnFZFEjr1zCsicMWpAA",
       "token_type":"example",
       "expires_in":3600,
       "refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA",
       "example_parameter":"example_value"
     }
neomerx commented 7 years ago

Passport settings has key KEY_TOKEN_CUSTOM_PROPERTIES_PROVIDER which could be set as an calalble method returning extra token properties. The signature of the method is the following

public static method tokenExtraMethodProvider(ContainerInterface $container, TokenInterface $token): array {
    retun ...;
}
neomerx commented 7 years ago

Passport settings could have a methods for adding extra properties

    /**
     * @inheritdoc
     */
    protected function getTokenCustomPropertiesProvider()
    {
        return [self::class,  'tokenCustomPropertiesProvider'];
    }

    public static function tokenCustomPropertiesProvider(ContainerInterface $container, TokenInterface $token): array
    {
        return [
            'user_id' => $token->getUserIdentifier(),
        ];
    }