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

Generalized access token format #874

Merged
merged 11 commits into from
May 24, 2018
Merged

Conversation

lookyman
Copy link
Contributor

Replacement for #873

Copy link

@simonhamp simonhamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could avoid a BC break if getResponseString was a new method that called convertToJWT in AccessTokenTrait.php. In case any implementors are relying on convertToJWT's existence.

@lookyman
Copy link
Contributor Author

We still need to call that new method from all places that currently call the old one though. Which means adding it to the access token interface, which means BC break if someone doesn't use the trait and just implements the interface.. But sure, I can do that.

@simonhamp
Copy link

I agree, but a BC break for some is better than a BC break for all IMHO :)

Thanks for changing that.

@frankdejonge
Copy link
Member

My two cents on the matter. The getResponseString is a very technical description. It might be better to name it something along the lines of convertToAccessToken with a string return type. This is a better description than "get string response". The current convertToJwt could be seen as an implementation detail of that function.

@Sephster
Copy link
Member

Great suggestion. Thanks @frankdejonge

*
* @return string
*/
public function getResponseString(CryptKey $privateKey);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @frankdejonge suggested, it would be good to change this to convertToAccessToken

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update it this evening.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this this morning @lookyman - hope that was ok but thought I'd save you the effort as it was a quick change.

@Sephster Sephster added this to the 8.00 milestone Apr 5, 2018
@@ -22,4 +22,13 @@
* @return Token
*/
public function convertToJWT(CryptKey $privateKey);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be removed from the interface as people who don't want to use JWTs for their access token's will have no need for this. This is going to be a breaking change which is why I've flagged this change for version 8.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@Sephster
Copy link
Member

I've removed the native type hints for now as I'd prefer these were implemented project wide instead of in sections of the code.

I think this is pretty close to being able to be merged in but I'm unsure about the new method name now I've reviewed it again.

In our code we now can have implementations as follows:

$this->accessToken->convertToAccessToken($this->privateKey);

This seems strange to me due to the naming we have used. Why would an access token object need to be converted to an access token? Its name implies it already is one. I'm worried that the current name of the function isn't clear enough.

I have been racking my brain trying to think of a more appropriate name. I had thought we could possibly use __toString() but it doesn't accept an argument meaning we would need to set the private key in advance which is probably more trouble than its worth.

The best name I've come up with at the moment is simple build, which would align it with the JWT libraries builder class. I think that it would make more sense to call the function this so the code would then read as follows, which to me, seems more natural/intuitive.

$this->accessToken->build($this->privateKey);

If you have any thoughts on this @lookyman - or anyone else for that matter, I would very much appreciate a second set of eyes for this proposed adjustment

@Sephster Sephster changed the base branch from master to 8.0.0 May 21, 2018 15:13
@Sephster
Copy link
Member

I've also changed this to merge into branch 8.0.0 which I created today

@lookyman
Copy link
Contributor Author

I don't really care about the method's name, I am fine either way.

I would however love to have it without the argument, and set the key in advance, to further separate it from any hardcoded implementation. But I understand if you don't want to go in that direction right now.

@Sephster
Copy link
Member

Hmmm. As far as I can tell, we set the private key for the response type but it is just passed to the access token. It might be more appropriate to set it on the access token as that is the entity that is using it. We can easily do this in the issueAccessToken function.

We could then use a __toString() magic method and do away with the instance on the response type if I haven't missed anything.

Do you want to have a go at implementing this @lookyman? If not, I'm happy to make the changes tomorrow. Cheers

@Sephster
Copy link
Member

I've updated the code @lookyman to use __toString() and set the private key in the access token for encryption. Let me know what you think. Cheers.

@lookyman
Copy link
Contributor Author

Thank you, I love it.

@Sephster Sephster dismissed their stale review May 24, 2018 09:59

Review for old version

@Sephster
Copy link
Member

Good stuff. I will merge it in now :) Cheers for all your efforts with this

@Sephster Sephster merged commit ca6be05 into thephpleague:8.0.0 May 24, 2018
@Sephster Sephster removed this from the 9.00 milestone Jul 25, 2019
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.

4 participants