| 790 | } |
| 791 | |
| 792 | bool JWTTokenAuth(ThriftServer::ConnectionContext* connection_context, |
| 793 | const AuthenticationHash& hash, const string& token) { |
| 794 | JWTHelper::UniqueJWTDecodedToken decoded_token; |
| 795 | Status status = JWTHelper::Decode(token, decoded_token); |
| 796 | if (!status.ok()) { |
| 797 | LOG(ERROR) << "Error decoding JWT token received from: " |
| 798 | << TNetworkAddressToString(connection_context->network_address) |
| 799 | << " Error: " << status; |
| 800 | return false; |
| 801 | } |
| 802 | if (FLAGS_jwt_validate_signature) { |
| 803 | status = ExecEnv::GetInstance()->GetJWTHelperInstance()->Verify(decoded_token.get()); |
| 804 | if (!status.ok()) { |
| 805 | LOG(ERROR) << "Error verifying JWT token received from: " |
| 806 | << TNetworkAddressToString(connection_context->network_address) |
| 807 | << " Error: " << status; |
| 808 | connection_context->return_headers.push_back( |
| 809 | Substitute("WWW-Authenticate: Bearer error=\"invalid_token\",\ |
| 810 | error_description=\"$0 \"", status.GetDetail())); |
| 811 | return false; |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | DCHECK(!FLAGS_jwt_custom_claim_username.empty()); |
| 816 | string username; |
| 817 | status = JWTHelper::GetCustomClaimUsername( |
| 818 | decoded_token.get(), FLAGS_jwt_custom_claim_username, username); |
| 819 | if (!status.ok()) { |
| 820 | LOG(ERROR) << "Error extracting username from JWT token received from: " |
| 821 | << TNetworkAddressToString(connection_context->network_address) |
| 822 | << " Error: " << status; |
| 823 | return false; |
| 824 | } |
| 825 | connection_context->username = username; |
| 826 | |
| 827 | // Create a cookie to return. |
| 828 | connection_context->return_headers.push_back( |
| 829 | Substitute("Set-Cookie: $0", GenerateCookie(username, hash, HTTP_AUTH_MECH_JWT))); |
| 830 | return true; |
| 831 | } |
| 832 | |
| 833 | bool OAuthTokenAuth(ThriftServer::ConnectionContext* connection_context, |
| 834 | const AuthenticationHash& hash, const string& token) { |
no test coverage detected