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

Improved OIDC compliance #386

Merged
merged 11 commits into from
Oct 30, 2019
Merged

Improved OIDC compliance #386

merged 11 commits into from
Oct 30, 2019

Conversation

joshcanhelp
Copy link
Contributor

@joshcanhelp joshcanhelp commented Oct 20, 2019

Changes

This update improves the SDK support for OpenID Connect. In particular, it modifies the sign in verification phase by substituting backchannel based checks with id_token validation.

References

Testing

  • This change adds test coverage
  • This change has been tested on PHP 7.1

Checklist

  • All existing and new tests complete without errors.
  • The correct base branch is being used.

@joshcanhelp joshcanhelp changed the base branch from master to 7.0.0-dev October 20, 2019 19:24
*
* @param array $jwks JWKS to use.
*/
public function __construct(array $jwks)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sample used a URL here but I don't think that HTTP requests and caching should be a part of this class, should be more focused on the task. See the code above to see how this would look in situ:

if ('RS256' === $this->idTokenAlg) {
    $jwksFetcher = new JWKFetcher($this->cacheHandler, $this->guzzleOptions);
    $jwks        = $jwksFetcher->getKeys($this->idTokenIss.'.well-known/jwks.json');
    $sigVerifier = new JwksVerifier( $jwks );
} else if ('HS256' === $this->idTokenAlg) {
    $sigVerifier = new SymmetricVerifier($this->clientSecret);
}


if ($now > $authValidUntil) {
throw new InvalidTokenException( sprintf(
'Authentication Time (auth_time) claim in the ID token indicates that too much time has passed since the last end-user authentication. Current time (%d) is after last auth at %d',
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 think this is worded incorrectly in the sample, now that I'm implementing. Shouldn't it say something like:

Current time (CURRENT_TIME_VALUE) is more than MAX_AGE_VALUE seconds after last auth at AUTH_TIME_VALUE

@joshcanhelp joshcanhelp changed the title Oidc improvements OIDC Improvements: ID Token Validation Oct 21, 2019
@joshcanhelp joshcanhelp marked this pull request as ready for review October 21, 2019 15:31
@joshcanhelp joshcanhelp requested a review from a team October 21, 2019 15:31
@joshcanhelp joshcanhelp added this to the 7.0.0 milestone Oct 21, 2019
@joshcanhelp joshcanhelp changed the title OIDC Improvements: ID Token Validation Improved OIDC compliance Oct 21, 2019
@joshcanhelp joshcanhelp removed the request for review from a team October 21, 2019 16:02
Copy link
Contributor

@lbalmaceda lbalmaceda left a comment

Choose a reason for hiding this comment

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

Skipped the tests for now

Copy link

@gkwang gkwang left a comment

Choose a reason for hiding this comment

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

lgtm.

src/Auth0.php Outdated
Comment on lines 362 to 366
if (isset($config['cache_handler']) && $config['cache_handler']) {
$this->cacheHandler = $config['cache_handler'];
} else {
$this->cacheHandler = new NoCacheHandler();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

$this->cacheHandler = $config['cache_handler'] ?? new NoCacheHandler();

?

Copy link
Contributor Author

@joshcanhelp joshcanhelp Oct 30, 2019

Choose a reason for hiding this comment

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

Better, I agree (still getting used to the fact that I can use null coalescing now). I also need to check that it's the right instance, though.

Will push a change for that now.

protected function checkSignature(Token $token) : bool
{
$tokenKid = $token->getHeader('kid', false);
if (! array_key_exists($tokenKid, $this->jwks)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would ! isset() or empty() make more sense here? The current code is not type safe, given that the Key constructor requires a string $content:

https://github.com/lcobucci/jwt/blob/bdaf6ae2a78ded9b0a9d2c087f63948bc26d58cd/src/Signer/Key.php#L26

Copy link
Contributor Author

@joshcanhelp joshcanhelp Oct 30, 2019

Choose a reason for hiding this comment

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

Good catch but we're using the stable 3.3 branch and that's not a concern:

https://github.com/lcobucci/jwt/blob/3.3/src/Signer/Key.php#L34

An empty value here will fail validation rather than throw a type error.

*/
abstract class SignatureVerifier
{

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

namespace Auth0\SDK\Helpers\Tokens;

use Auth0\SDK\Exception\InvalidTokenException;
use stdClass;
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't appear to be used.

@shadowhand
Copy link
Contributor

Oops, looks like I commented on something in the middle of rebase. 😅

@joshcanhelp
Copy link
Contributor Author

@shadowhand - Yeah, my fault ... bad master rebase rather than 7.0.0-dev 😬

@auth0 auth0 deleted a comment from shadowhand Oct 30, 2019
@auth0 auth0 deleted a comment from shadowhand Oct 30, 2019
@auth0 auth0 deleted a comment from shadowhand Oct 30, 2019
@auth0 auth0 deleted a comment from shadowhand Oct 30, 2019
@auth0 auth0 deleted a comment from shadowhand Oct 30, 2019
@auth0 auth0 deleted a comment from shadowhand Oct 30, 2019
@joshcanhelp joshcanhelp merged commit 246891d into 7.0.0-dev Oct 30, 2019
@joshcanhelp joshcanhelp deleted the oidc-improvements branch October 30, 2019 22:02
@github-actions
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants