Encodes a claim for a JSON web token (JWT) to make an OAuth request.
| 130 | |
| 131 | /// Encodes a claim for a JSON web token (JWT) to make an OAuth request. |
| 132 | Status EncodeJwtClaim(StringPiece client_email, StringPiece scope, |
| 133 | StringPiece audience, uint64 request_timestamp_sec, |
| 134 | string* encoded) { |
| 135 | // Step 1: create the JSON with the claim. |
| 136 | Json::Value root; |
| 137 | root["iss"] = Json::Value(client_email.begin(), client_email.end()); |
| 138 | root["scope"] = Json::Value(scope.begin(), scope.end()); |
| 139 | root["aud"] = Json::Value(audience.begin(), audience.end()); |
| 140 | |
| 141 | const auto expiration_timestamp_sec = |
| 142 | request_timestamp_sec + kRequestedTokenLifetimeSec; |
| 143 | |
| 144 | root["iat"] = Json::Value::UInt64(request_timestamp_sec); |
| 145 | root["exp"] = Json::Value::UInt64(expiration_timestamp_sec); |
| 146 | |
| 147 | // Step 2: represent the JSON as a string. |
| 148 | string claim = root.toStyledString(); |
| 149 | |
| 150 | // Step 3: encode the string as base64. |
| 151 | return Base64Encode(claim, encoded); |
| 152 | } |
| 153 | |
| 154 | /// Encodes a header for a JSON web token (JWT) to make an OAuth request. |
| 155 | Status EncodeJwtHeader(StringPiece key_id, string* encoded) { |
no test coverage detected