| 40 | namespace { |
| 41 | |
| 42 | Try<JSON::Object> decode(const string& component) |
| 43 | { |
| 44 | const Try<string> decoded = base64::decode_url_safe(component); |
| 45 | |
| 46 | if (decoded.isError()) { |
| 47 | return Error("Failed to base64url-decode: " + decoded.error()); |
| 48 | } |
| 49 | |
| 50 | const Try<JSON::Object> json = JSON::parse<JSON::Object>(decoded.get()); |
| 51 | |
| 52 | if (json.isError()) { |
| 53 | return Error("Failed to parse into JSON: " + json.error()); |
| 54 | } |
| 55 | |
| 56 | return json; |
| 57 | } |
| 58 | |
| 59 | |
| 60 | Try<JWT::Header> parse_header(const string& component) |