Encodes a header for a JSON web token (JWT) to make an OAuth request.
| 153 | |
| 154 | /// Encodes a header for a JSON web token (JWT) to make an OAuth request. |
| 155 | Status EncodeJwtHeader(StringPiece key_id, string* encoded) { |
| 156 | // Step 1: create the JSON with the header. |
| 157 | Json::Value root; |
| 158 | root["alg"] = kCryptoAlgorithm; |
| 159 | root["typ"] = kJwtType; |
| 160 | root["kid"] = Json::Value(key_id.begin(), key_id.end()); |
| 161 | |
| 162 | // Step 2: represent the JSON as a string. |
| 163 | const string header = root.toStyledString(); |
| 164 | |
| 165 | // Step 3: encode the string as base64. |
| 166 | return Base64Encode(header, encoded); |
| 167 | } |
| 168 | |
| 169 | } // namespace |
| 170 |
no test coverage detected