Skip to content

added easier method to customize jwt token payload#795

Merged
bshaffer merged 2 commits into
bshaffer:developfrom
svycka:feature/issue-793-customize-jwt-payload
Jan 11, 2017
Merged

added easier method to customize jwt token payload#795
bshaffer merged 2 commits into
bshaffer:developfrom
svycka:feature/issue-793-customize-jwt-payload

Conversation

@svycka
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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

@MajesticMaje
Copy link
Copy Markdown

Any word on this? Would be a big help!

@svycka
Copy link
Copy Markdown
Contributor Author

svycka commented Sep 7, 2017 via email

@bluebaroncanada
Copy link
Copy Markdown
Collaborator

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

@bluebaroncanada
Copy link
Copy Markdown
Collaborator

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

@bshaffer
Copy link
Copy Markdown
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