当前位置: 首页>>代码示例>>Java>>正文


Java JsonWebSignature.Header方法代码示例

本文整理汇总了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);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:35,代码来源:FirebaseTokenFactory.java

示例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;
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:8,代码来源:FirebaseTokenVerifierTest.java

示例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;
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:34,代码来源:CredentialFactory.java

示例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);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:5,代码来源:FirebaseTokenVerifierTest.java


注:本文中的com.google.api.client.json.webtoken.JsonWebSignature.Header方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。