MCPcopy Create free account
hub / github.com/apache/mesos / parse

Method parse

3rdparty/libprocess/src/jwt.cpp:183–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181
182
183Try<JWT, JWTError> JWT::parse(const std::string& token)
184{
185 const vector<string> components = strings::split(token, ".");
186
187 if (components.size() != 3) {
188 return JWTError(
189 "Expected 3 components in token, got " + stringify(components.size()),
190 JWTError::Type::INVALID_TOKEN);
191 }
192
193 Try<JWT::Header> header = parse_header(components[0]);
194
195 if (header.isError()) {
196 return JWTError(header.error(), JWTError::Type::INVALID_TOKEN);
197 }
198
199 if (header->alg != JWT::Alg::None) {
200 return JWTError(
201 "Token 'alg' value \"" + stringify(header->alg) +
202 "\" does not match, expected \"none\"",
203 JWTError::Type::INVALID_TOKEN);
204 }
205
206 Try<JSON::Object> payload = parse_payload(components[1]);
207
208 if (payload.isError()) {
209 return JWTError(payload.error(), JWTError::Type::INVALID_TOKEN);
210 }
211
212 if (!components[2].empty()) {
213 return JWTError(
214 "Unsecured JWT contains a signature",
215 JWTError::Type::INVALID_TOKEN);
216 }
217
218 return JWT(header.get(), payload.get(), None());
219}
220
221
222Try<JWT, JWTError> JWT::parse(const string& token, const string& secret)

Callers

nothing calls this directly

Calls 15

splitFunction · 0.85
JWTErrorClass · 0.85
parse_headerFunction · 0.85
parse_payloadFunction · 0.85
JWTClass · 0.85
NoneClass · 0.85
decode_url_safeFunction · 0.85
generate_hmac_sha256Function · 0.85
constantTimeEqualsFunction · 0.85
verify_rsa_sha256Function · 0.85
errorMethod · 0.65
stringifyClass · 0.50

Tested by

no test coverage detected