Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve redirect_login error logging, JWT leeway #317

Merged
merged 1 commit into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/WP_Auth0_LoginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,13 @@ public function redirect_login() {
$data->id_token = null;
$response = WP_Auth0_Api_Client::get_user_info( $domain, $data->access_token );
} else {
// grab the user ID from the id_token to call get_user
$decodedToken = JWT::decode( $data->id_token, $this->a0_options->get_client_secret_as_key(), array( 'HS256' ) );
try {
// grab the user ID from the id_token to call get_user
$decodedToken = JWT::decode( $data->id_token, $this->a0_options->get_client_secret_as_key(), array( 'HS256' ) );
} catch (Exception $e) {
WP_Auth0_ErrorManager::insert_auth0_error('redirect_login/decode', $e->getMessage());
throw new WP_Auth0_LoginFlowValidationException(__('Error: There was an issue decoding the token', WPA0_LANG));
}

// validate that this JWT was made for us
if ( $this->a0_options->get( 'client_id' ) !== $decodedToken->aud ) {
Expand Down
16 changes: 8 additions & 8 deletions lib/php-jwt/Authentication/JWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,24 @@ public static function decode($jwt, $key = null, $allowed_algs = array())
}

// Check if the nbf if it is defined. This is the time that the
// token can actually be used. If it's not yet that time, abort.
if (isset($payload->nbf) && $payload->nbf > time()) {
// token can actually be used. If it's not yet that time, abort. Small leeway for clock skew.
if (isset($payload->nbf) && $payload->nbf > time() + 2) {
throw new BeforeValidException(
'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->nbf)
'Cannot handle token prior to (nbf) ' . date(DateTime::ISO8601, $payload->nbf)
);
}

// Check that this token has been created before 'now'. This prevents
// using tokens that have been created for later use (and haven't
// correctly used the nbf claim).
if (isset($payload->iat) && $payload->iat > time()) {
// correctly used the nbf claim). Small leeway for clock skew.
if (isset($payload->iat) && $payload->iat > time() + 2) {
throw new BeforeValidException(
'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->iat)
'Cannot handle token prior to (iat) ' . date(DateTime::ISO8601, $payload->iat)
);
}

// Check if this token has expired.
if (isset($payload->exp) && time() >= $payload->exp) {
// Check if this token has expired. Small leeway for clock skew.
if (isset($payload->exp) && time() >= $payload->exp + 2) {
throw new ExpiredException('Expired token');
}
}
Expand Down