JWTPublicKey member functions. Verify JWT's signature for the given decoded token with jwt-cpp API.
| 273 | // |
| 274 | // Verify JWT's signature for the given decoded token with jwt-cpp API. |
| 275 | Status JWTPublicKey::Verify( |
| 276 | const DecodedJWT& decoded_jwt, const std::string& algorithm) const { |
| 277 | // Verify if algorithms are matching. |
| 278 | if (algorithm_.compare(algorithm) != 0) { |
| 279 | return Status(TErrorCode::JWT_VERIFY_FAILED, |
| 280 | Substitute("JWT algorithm '$0' is not matching with JWK algorithm '$1'", |
| 281 | algorithm, algorithm_)); |
| 282 | } |
| 283 | |
| 284 | Status status; |
| 285 | try { |
| 286 | // Call jwt-cpp API to verify token's signature. |
| 287 | verifier_.verify(decoded_jwt); |
| 288 | } catch (const jwt::error::rsa_exception& e) { |
| 289 | status = Status(TErrorCode::JWT_VERIFY_FAILED, Substitute("RSA error: $0", e.what())); |
| 290 | } catch (const jwt::error::token_verification_exception& e) { |
| 291 | status = Status(TErrorCode::JWT_VERIFY_FAILED, |
| 292 | Substitute("Verification failed, error: $0", e.what())); |
| 293 | } catch (const std::exception& e) { |
| 294 | status = Status(TErrorCode::JWT_VERIFY_FAILED, |
| 295 | Substitute("Varification failed, error: $0", e.what())); |
| 296 | } |
| 297 | return status; |
| 298 | } |
| 299 | |
| 300 | // Create a JWKPublicKey of HS from the JWK. |
| 301 | Status HSJWTPublicKeyBuilder::CreateJWKPublicKey( |