本文整理汇总了Java中com.google.api.client.json.webtoken.JsonWebSignature.Header方法的典型用法代码示例。如果您正苦于以下问题:Java JsonWebSignature.Header方法的具体用法?Java JsonWebSignature.Header怎么用?Java JsonWebSignature.Header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.json.webtoken.JsonWebSignature
的用法示例。
在下文中一共展示了JsonWebSignature.Header方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSignedCustomAuthTokenForUser
import com.google.api.client.json.webtoken.JsonWebSignature; //导入方法依赖的package包/类
public String createSignedCustomAuthTokenForUser(
String uid, Map<String, Object> developerClaims, String issuer, PrivateKey privateKey)
throws GeneralSecurityException, IOException {
Preconditions.checkState(uid != null, "Uid must be provided.");
Preconditions.checkState(issuer != null && !"".equals(issuer), "Must provide an issuer.");
Preconditions.checkState(uid.length() <= 128, "Uid must be shorter than 128 characters.");
JsonWebSignature.Header header = new JsonWebSignature.Header().setAlgorithm("RS256");
long issuedAt = clock.currentTimeMillis() / 1000;
FirebaseCustomAuthToken.Payload payload =
new FirebaseCustomAuthToken.Payload()
.setUid(uid)
.setIssuer(issuer)
.setSubject(issuer)
.setAudience(FirebaseCustomAuthToken.FIREBASE_AUDIENCE)
.setIssuedAtTimeSeconds(issuedAt)
.setExpirationTimeSeconds(issuedAt + FirebaseCustomAuthToken.TOKEN_DURATION_SECONDS);
if (developerClaims != null) {
Collection<String> reservedNames = payload.getClassInfo().getNames();
for (String key : developerClaims.keySet()) {
if (reservedNames.contains(key)) {
throw new IllegalArgumentException(
String.format("developer_claims can not contain a reserved key: %s", key));
}
}
GenericJson jsonObject = new GenericJson();
jsonObject.putAll(developerClaims);
payload.setDeveloperClaims(jsonObject);
}
return JsonWebSignature.signUsingRsaSha256(privateKey, factory, header, payload);
}
示例2: createHeader
import com.google.api.client.json.webtoken.JsonWebSignature; //导入方法依赖的package包/类
private JsonWebSignature.Header createHeader() throws Exception {
JsonWebSignature.Header header = new JsonWebSignature.Header();
header.setAlgorithm(ALGORITHM);
header.setType("JWT");
header.setKeyId(PRIVATE_KEY_ID);
return header;
}
示例3: executeRefreshToken
import com.google.api.client.json.webtoken.JsonWebSignature; //导入方法依赖的package包/类
@Override
protected TokenResponse executeRefreshToken() throws IOException {
if (getServiceAccountPrivateKey() == null) {
return super.executeRefreshToken();
}
// service accounts: no refresh token; instead use private key to request new access token
JsonWebSignature.Header header = new JsonWebSignature.Header();
header.setAlgorithm("RS256");
header.setType("JWT");
header.setKeyId(getServiceAccountPrivateKeyId());
JsonWebToken.Payload payload = new JsonWebToken.Payload();
long currentTime = getClock().currentTimeMillis();
payload.setIssuer(getServiceAccountId());
payload.setAudience(getTokenServerEncodedUrl());
payload.setIssuedAtTimeSeconds(currentTime / 1000);
payload.setExpirationTimeSeconds(currentTime / 1000 + DEFAULT_TOKEN_EXPIRATION_SECONDS);
payload.setSubject(getServiceAccountUser());
payload.put("scope", Joiner.on(' ').join(getServiceAccountScopes()));
try {
String assertion = JsonWebSignature.signUsingRsaSha256(
getServiceAccountPrivateKey(), getJsonFactory(), header, payload);
TokenRequest request = new TokenRequest(
getTransport(), getJsonFactory(), new GenericUrl(getTokenServerEncodedUrl()),
"urn:ietf:params:oauth:grant-type:jwt-bearer");
request.put("assertion", assertion);
request.setRequestInitializer(getRequestInitializer());
return request.execute();
} catch (GeneralSecurityException exception) {
IOException e = new IOException();
e.initCause(exception);
throw e;
}
}
示例4: createToken
import com.google.api.client.json.webtoken.JsonWebSignature; //导入方法依赖的package包/类
private String createToken(JsonWebSignature.Header header, JsonWebToken.Payload payload)
throws GeneralSecurityException, IOException {
return JsonWebSignature.signUsingRsaSha256(privateKey, FACTORY, header, payload);
}