-
Notifications
You must be signed in to change notification settings - Fork 216
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
feat(SDK-4731): Implement support for Back-Channel Logout #747
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #747 +/- ##
===========================================
Coverage 100.00% 100.00%
- Complexity 1339 1378 +39
===========================================
Files 62 62
Lines 4671 4769 +98
===========================================
+ Hits 4671 4769 +98
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@@ -28,7 +28,7 @@ | |||
], | |||
"homepage": "https://github.com/auth0/auth0-PHP", | |||
"require": { | |||
"php": "^8.0", | |||
"php": "^8.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PHP 8.0 has been deprecated, so we'll drop support with this coming release. This PR includes new language features that rely on 8.1+, so just going ahead and bumping it here.
$sub = $token->getSubject() ?? ''; | ||
$iss = $token->getIssuer() ?? ''; | ||
$sid = $token->getIdentifier() ?? ''; | ||
$this->setBackchannel(hash('sha256', implode('|', [$sub, $iss, $sid]))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would only expect you to set the backchannel logout cache item when you get the back-channel webhook. What is happening here on login?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a workaround because the PHP SDK doesn't use persistent session identifiers that we could previously tie to a backchannel request. Basically just a UUID for the session. This allows us to tie a potential incoming webhook we receive later on to this particular session. (It's stored in the JSON struct of the device cookie, and not a query to the server-side cache itself.)
src/Auth0.php
Outdated
])); | ||
|
||
// Let the backchannel logout request fall off after a reasonable amount of time. | ||
$request->expiresAfter(time() + (86400 * 30)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a session duration setting you can set this to? (shortest of rolling or absolute duration)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Updated to make this configurable; a new option is exposed during SDK initialization (the SdkConfiguration
class), backchannelLogoutExpires
. It still defaults to 30 days to cover some funky edge cases I can foresee with rolling sessions under certain circumstances.
$cache = $this->configuration()->getBackchannelLogoutCache(); | ||
|
||
// Does the session have a backchannel key available for lookup? | ||
$backchannel = $state->getBackchannel(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is expensive or not? If it is, it should be behind the backchannel enabled config (which I assume is $cache instanceof \Psr\Cache\CacheItemPoolInterface
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appreciate the caution, but should be all good:
-
$cache
will benull
if Backchannel is not configured for the SDK, and thus ignored. Otherwise, the cache will have been initialized along with the SDK at runtime by necessity. It only occurs max once per request, and I imagine in 99% of cases will be the same cache resource the developer is already using for other things, like JWKS caching, so overhead will likely be non-existent in most applications. -
setBackchannel()
just reads the string UUID stored in the device cookie's JSON structure, which is already extracted and decoded at request time.
**Added** - feat(SDK-4731): Implement support for Back-Channel Logout [\#747](#747) ([evansims](https://github.com/evansims)) **Changed** - PHP 8.1 is now the minimum supported runtime [\#748](#748) ([evansims](https://github.com/evansims))
Changes
This PR implements support for Back-Channel Logout.
References
See internal ticket SDK-4720.
Testing
Tests have been updated to add coverage for these new features.
Contributor Checklist