MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / EncodeJwtClaim

Function EncodeJwtClaim

tensorflow/core/platform/cloud/oauth_client.cc:132–152  ·  view source on GitHub ↗

Encodes a claim for a JSON web token (JWT) to make an OAuth request.

Source from the content-addressed store, hash-verified

130
131/// Encodes a claim for a JSON web token (JWT) to make an OAuth request.
132Status 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.
155Status EncodeJwtHeader(StringPiece key_id, string* encoded) {

Callers 1

Calls 4

Base64EncodeFunction · 0.85
ValueFunction · 0.50
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected