Skip to content

feat: Add support for device code grant#229

Merged
chalasr merged 1 commit intothephpleague:masterfrom
SimonVanacco:master
Mar 21, 2026
Merged

feat: Add support for device code grant#229
chalasr merged 1 commit intothephpleague:masterfrom
SimonVanacco:master

Conversation

@SimonVanacco
Copy link
Copy Markdown
Contributor

@SimonVanacco SimonVanacco commented Mar 25, 2025

This PR adds support for device code grants, which has been available for some time in oauth2-server

Ready to be tested, I'd love to get some feedback if you think some areas could be improved !

Design considerations

  • I've decided to let end-users handle the device code verification page on their own. This is to prevent having to require twig in the bundle itself and create more complexity to accommodate all use cases. An example controller has been added in the documentation
  • This does not support verification_uri_complete, only verification_uri
  • Logic for code approval is in DeviceCodeRepository::approveDeviceCode. I was unable to re-use the logic from oauth2-server as they fetch the code by "device_code" instead of by "user_code". Not sure if this is a mistake in the parent bundle or some use-case I don't understand, but it does not accommodate most people use-cases. I'm open to moving the logic somewhere else if you find a better place for it !
  • I've added some basic tests but this is not my strong suit : please let me know if I missed something :)

Copy link
Copy Markdown
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Can you rebase it? Here are some comments also

Comment thread docs/device-code-grant.md Outdated
Comment thread docs/device-code-grant.md Outdated
Comment thread docs/device-code-grant.md
Comment thread src/Manager/Doctrine/DeviceCodeManager.php
SimonVanacco added a commit to SimonVanacco/oauth2-server-bundle that referenced this pull request Apr 26, 2025
SimonVanacco added a commit to SimonVanacco/oauth2-server-bundle that referenced this pull request Apr 26, 2025
@SimonVanacco
Copy link
Copy Markdown
Contributor Author

Hi @chalasr

I'm not entirely sure I understood correctly what you wanted for the docs/device-code-grant.md improvements, but I tried my best to fit to your feedback :)

PR is rebased !

@Mika56
Copy link
Copy Markdown

Mika56 commented Oct 20, 2025

Interested in this PR, but there's been no activity for a few months. Anything we can do to help?

@Renrhaf
Copy link
Copy Markdown

Renrhaf commented Oct 21, 2025

+1 interested as well !

Copy link
Copy Markdown
Collaborator

@ajgarlag ajgarlag left a comment

Choose a reason for hiding this comment

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

Thank you for your work here. I've managed to create a working demo. I've reviewed your code and added some suggestions.

Comment thread src/DependencyInjection/Configuration.php
Comment thread src/Manager/DeviceCodeManagerInterface.php Outdated
Comment thread src/Repository/ClientRepository.php Outdated
Comment thread src/Repository/DeviceCodeRepository.php Outdated
Comment thread src/DependencyInjection/Configuration.php
Comment thread src/Repository/DeviceCodeRepository.php Outdated
@chalasr
Copy link
Copy Markdown
Member

chalasr commented Nov 17, 2025

Happy to merge once Antonio's review comments are resolved.

@ajgarlag
Copy link
Copy Markdown
Collaborator

ajgarlag commented Dec 2, 2025

@SimonVanacco Friendly ping

SimonVanacco added a commit to SimonVanacco/oauth2-server-bundle that referenced this pull request Dec 2, 2025
@SimonVanacco
Copy link
Copy Markdown
Contributor Author

Hi @ajgarlag

Thank you for the review, and sorry for the delay. The past few weeks have been a bit hectic :)

I implemented some of your requests (new configuration options, refactoring of the repository) and left comments on the ones I won't be able to do myself without some guidance : Supporting Symfony routes for the verification_uri and removing approveDeviceCode.

Let me know your thoughts on the update and I'll try to be quicker to respond now !

@chalasr
Copy link
Copy Markdown
Member

chalasr commented Dec 2, 2025

Thanks. Supporting route names can be done in a follow-up PR, no problem. Regarding approveDeviceCode, I'll let Antonio have the final word as I have no strong opinion.

Comment thread src/Repository/DeviceCodeRepository.php Outdated
Comment thread src/Repository/DeviceCodeRepository.php Outdated
Comment thread src/Repository/DeviceCodeRepository.php Outdated
Comment thread src/Repository/DeviceCodeRepository.php Outdated
@chalasr
Copy link
Copy Markdown
Member

chalasr commented Feb 6, 2026

@SimonVanacco can you look into last comments sometime?

ajgarlag pushed a commit that referenced this pull request Feb 11, 2026
SimonVanacco added a commit to SimonVanacco/oauth2-server-bundle that referenced this pull request Feb 22, 2026
@SimonVanacco SimonVanacco force-pushed the master branch 3 times, most recently from 2071145 to 2166526 Compare February 22, 2026 16:19
@SimonVanacco
Copy link
Copy Markdown
Contributor Author

Hi @chalasr @ajgarlag

All request changed have been implemented. My branch has been rebased and support for PHP 8.5 added as well

Sorry for the delay and messy rebase !

Comment thread src/Model/DeviceCodeInterface.php
Comment thread src/Model/DeviceCode.php
Comment thread src/Model/DeviceCode.php
Comment thread src/Repository/DeviceCodeRepository.php Outdated
Comment thread src/Model/DeviceCode.php Outdated
@ajgarlag
Copy link
Copy Markdown
Collaborator

@SimonVanacco Thanks for your work here. I've sent a few final suggestions.

@SimonVanacco
Copy link
Copy Markdown
Contributor Author

@SimonVanacco Thanks for your work here. I've sent a few final suggestions.

The latest commit should address your suggestions, thank you for the thorough review !

Copy link
Copy Markdown
Collaborator

@ajgarlag ajgarlag left a comment

Choose a reason for hiding this comment

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

@SimonVanacco Great work! Could you please squash your commits?

@chalasr Would you like to do a final review?

@SimonVanacco
Copy link
Copy Markdown
Contributor Author

Commits squashed :)

@chalasr
Copy link
Copy Markdown
Member

chalasr commented Mar 21, 2026

Great job! Thank you @SimonVanacco 🚀

@chalasr chalasr merged commit 9388fec into thephpleague:master Mar 21, 2026
32 checks passed
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