本文整理汇总了Java中com.google.api.client.json.webtoken.JsonWebSignature类的典型用法代码示例。如果您正苦于以下问题:Java JsonWebSignature类的具体用法?Java JsonWebSignature怎么用?Java JsonWebSignature使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonWebSignature类属于com.google.api.client.json.webtoken包,在下文中一共展示了JsonWebSignature类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: parse
import com.google.api.client.json.webtoken.JsonWebSignature; //导入依赖的package包/类
static FirebaseToken parse(JsonFactory jsonFactory, String tokenString) throws IOException {
try {
JsonWebSignature jws =
JsonWebSignature.parser(jsonFactory)
.setPayloadClass(FirebaseTokenImpl.Payload.class)
.parse(tokenString);
return new FirebaseToken(
new FirebaseTokenImpl(
jws.getHeader(),
(FirebaseTokenImpl.Payload) jws.getPayload(),
jws.getSignatureBytes(),
jws.getSignedContentBytes()));
} catch (IOException e) {
throw new IOException(
"Decoding Firebase ID token failed. Make sure you passed the entire string JWT "
+ "which represents an ID token. See https://firebase.google.com/docs/auth/admin/"
+ "verify-id-tokens for details on how to retrieve an ID token.",
e);
}
}
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:21,代码来源:FirebaseToken.java
示例2: 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);
}
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:35,代码来源:FirebaseTokenFactory.java
示例3: parse
import com.google.api.client.json.webtoken.JsonWebSignature; //导入依赖的package包/类
/** Parses a JWT token string and extracts its headers and payload fields. */
public static FirebaseCustomAuthToken parse(JsonFactory jsonFactory, String tokenString)
throws IOException {
JsonWebSignature jws =
JsonWebSignature.parser(jsonFactory).setPayloadClass(Payload.class).parse(tokenString);
return new FirebaseCustomAuthToken(
jws.getHeader(),
(Payload) jws.getPayload(),
jws.getSignatureBytes(),
jws.getSignedContentBytes());
}
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:12,代码来源:FirebaseCustomAuthToken.java
示例4: 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;
}
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:8,代码来源:FirebaseTokenVerifierTest.java
示例5: verifySignature
import com.google.api.client.json.webtoken.JsonWebSignature; //导入依赖的package包/类
public static boolean verifySignature(JsonWebSignature token, List<PublicKey> keys)
throws Exception {
for (PublicKey key : keys) {
if (token.verifySignature(key)) {
return true;
}
}
return false;
}
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:10,代码来源:TestUtils.java
示例6: getServiceAccountToken
import com.google.api.client.json.webtoken.JsonWebSignature; //导入依赖的package包/类
private String getServiceAccountToken(GoogleCredential credential, String targetAudience)
throws IOException, GeneralSecurityException {
final TokenRequest request = new TokenRequest(
this.httpTransport, JSON_FACTORY,
new GenericUrl(credential.getTokenServerEncodedUrl()),
"urn:ietf:params:oauth:grant-type:jwt-bearer");
final Header header = jwtHeader();
final Payload payload = jwtPayload(
targetAudience, credential.getServiceAccountId(), credential.getTokenServerEncodedUrl());
request.put("assertion", JsonWebSignature.signUsingRsaSha256(
credential.getServiceAccountPrivateKey(), JSON_FACTORY, header, payload));
final TokenResponse response = request.execute();
return (String) response.get("id_token");
}
开发者ID:spotify,项目名称:styx,代码行数:15,代码来源:GoogleIdTokenAuth.java
示例7: JSONWebToken
import com.google.api.client.json.webtoken.JsonWebSignature; //导入依赖的package包/类
public JSONWebToken(String emailAddress, Collection<String> scopes, PrivateKey privateKey)
throws GeneralSecurityException, IOException {
Payload payload = new Payload();
// Get current time in second.
long currentTime = TimeUnit.SECONDS.convert(Utils.getNowMicrosUtc(), TimeUnit.MICROSECONDS);
payload.setIssuer(emailAddress);
payload.setAudience(TOKEN_REQUEST_URI);
payload.setIssuedAtTimeSeconds(currentTime);
// Access token will expire in one hour.
payload.setExpirationTimeSeconds(currentTime + ONE_HOUR_IN_SECOND);
payload.put(SCOPE, Joiner.on(' ').join(scopes));
this.assertion = JsonWebSignature.signUsingRsaSha256(privateKey, JSON_FACTORY, HEADER, payload);
}
开发者ID:vmware,项目名称:photon-model,代码行数:14,代码来源:JSONWebToken.java
示例8: 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;
}
}
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:34,代码来源:CredentialFactory.java
示例9: 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);
}
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:5,代码来源:FirebaseTokenVerifierTest.java
注:本文中的com.google.api.client.json.webtoken.JsonWebSignature类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论