Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added easier method to customize jwt token payload #795

Merged

Conversation

svycka
Copy link
Contributor

@svycka svycka commented Jan 10, 2017

as suggested in #793
@bshaffer is it something like this?

usage example:

class MyJwtToken extends \OAuth2\ResponseType\JwtAccessToken
{
    protected function createPayload($client_id, $user_id, $scope = null)
    {
        $payload = parent::createPayload($client_id, $user_id, $scope);
        $payload['custom_param'] = 'my important value';

        return $payload;
    }
}


$server = new OAuth2\Server($storage, $config);

$jwtTokenResponseType = new MyJwtToken($publicKeyStorage, $accessTokenStorage, $refreshTokenStorage, $config);
$server->addResponseType($jwtTokenResponseType, 'token');

@bshaffer
Copy link
Owner

This is great! I'm being picky here, but I don't think the term generate is accurate for this case. I'd prefer the method be createPayload. Can you make this change?

@svycka
Copy link
Contributor Author

svycka commented Jan 11, 2017

@bshaffer done. I always have problems choosing names :) thought if we have generateAccessToken() generateRefreshToken() then why not generatePayload() :D not sure why those different. But anyway I did the change is it ok now? Also not sure but I guess tests are not required in this case?

@bshaffer
Copy link
Owner

@svycka I don't think tests are necessary for such a small refactoring.

As for the name, with the previous examples, the "generate" refers to the randomization of the token ID. In this case, the method is just constructing the payload and not really generating anything. That's my reasoning.

@bshaffer bshaffer merged commit d5b8a91 into bshaffer:develop Jan 11, 2017
@bshaffer
Copy link
Owner

Thank you for the PR!

@svycka svycka deleted the feature/issue-793-customize-jwt-payload branch January 12, 2017 06:27
@svycka
Copy link
Contributor Author

svycka commented Jan 23, 2017

@bshaffer is it possible that this will be merged soon? or should I go with workaround for now?

@ElectroLutz
Copy link

Is there an estimated date when this will be in a release? I find it very useful.

@MajesticMaje
Copy link

Any word on this? Would be a big help!

@svycka
Copy link
Contributor Author

svycka commented Sep 7, 2017 via email

@bluebaroncanada
Copy link
Collaborator

Yeah. Sorry. I thought you were saying, "Closed because it's not easy to do."

@bluebaroncanada
Copy link
Collaborator

@MajesticMaje so if you use the develop branch, you should be all set.

@bshaffer
Copy link
Owner

@MajesticMaje @svycka @bluebaroncanada Sorry for the delay here, we're all tagged up! Please update your dependencies for ^1.10:

composer require bshaffer/oauth2-server-php:^1.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants