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

feat(SDK-4731): Implement support for Back-Channel Logout #747

Merged
merged 23 commits into from
Dec 5, 2023

Conversation

evansims
Copy link
Member

@evansims evansims commented Dec 2, 2023

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

@evansims evansims added Scope: Improvement Code changes including new features or enhancements to the library. Roadmap: Next Minor Targets the next minor release of the library. labels Dec 2, 2023
@codecov-commenter
Copy link

codecov-commenter commented Dec 2, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c0720c2) 100.00% compared to head (00db0fe) 100.00%.

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     
Flag Coverage Δ
unittestsvalidate 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -28,7 +28,7 @@
],
"homepage": "https://github.com/auth0/auth0-PHP",
"require": {
"php": "^8.0",
"php": "^8.1",
Copy link
Member Author

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])));
Copy link
Contributor

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?

Copy link
Member Author

@evansims evansims Dec 4, 2023

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));
Copy link
Contributor

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)

Copy link
Member Author

@evansims evansims Dec 4, 2023

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();
Copy link
Contributor

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)

Copy link
Member Author

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 be null 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.

@evansims evansims merged commit f47439d into main Dec 5, 2023
@evansims evansims deleted the feat/oidc-backchannel-logout branch December 5, 2023 15:58
@evansims evansims mentioned this pull request Dec 5, 2023
evansims added a commit that referenced this pull request Dec 5, 2023
**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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Roadmap: Next Minor Targets the next minor release of the library. Scope: Improvement Code changes including new features or enhancements to the library.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants