Java Code Examples for org.apache.cxf.rs.security.oauth2.utils.OAuthUtils#getIssuedAt()

The following examples show how to use org.apache.cxf.rs.security.oauth2.utils.OAuthUtils#getIssuedAt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BigQueryServer.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static ClientAccessToken getAccessToken(PrivateKey privateKey, String issuer) {
    JwsHeaders headers = new JwsHeaders(JoseType.JWT, SignatureAlgorithm.RS256);
    JwtClaims claims = new JwtClaims();
    claims.setIssuer(issuer);
    claims.setAudience("https://www.googleapis.com/oauth2/v3/token");

    long issuedAt = OAuthUtils.getIssuedAt();
    claims.setIssuedAt(issuedAt);
    claims.setExpiryTime(issuedAt + 60 * 60);
    claims.setProperty("scope", "https://www.googleapis.com/auth/bigquery.readonly");

    JwtToken token = new JwtToken(headers, claims);
    JwsJwtCompactProducer p = new JwsJwtCompactProducer(token);
    String base64UrlAssertion = p.signWith(privateKey);

    JwtBearerGrant grant = new JwtBearerGrant(base64UrlAssertion);

    WebClient accessTokenService = WebClient.create("https://www.googleapis.com/oauth2/v3/token",
                                                    Arrays.asList(new OAuthJSONProvider(),
                                                                  new AccessTokenGrantWriter()));
    WebClient.getConfig(accessTokenService).getInInterceptors().add(new LoggingInInterceptor());

    accessTokenService.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_JSON);

    return accessTokenService.post(grant, ClientAccessToken.class);
}
 
Example 2
Source File: TokenCache.java    From g-suite-identity-sync with Apache License 2.0 5 votes vote down vote up
private ClientAccessToken getAccessToken() throws NoPrivateKeyException {
    JwsHeaders headers = new JwsHeaders(JoseType.JWT, SignatureAlgorithm.RS256);
    JwtClaims claims = new JwtClaims();
    claims.setIssuer(config.getServiceAccountEmail());
    claims.setAudience(config.getServiceAccountTokenUri());
    claims.setSubject(config.getServiceAccountSubject());

    long issuedAt = OAuthUtils.getIssuedAt();
    long tokenTimeout = config.getServiceAccountTokenLifetime();
    claims.setIssuedAt(issuedAt);
    claims.setExpiryTime(issuedAt + tokenTimeout);
    String scopes = String.join(" ", config.getServiceAccountScopes());
    claims.setProperty("scope", scopes);

    JwtToken token = new JwtToken(headers, claims);
    JwsJwtCompactProducer p = new JwsJwtCompactProducer(token);
    String base64UrlAssertion = p.signWith(config.readServiceAccountKey());

    JwtBearerGrant grant = new JwtBearerGrant(base64UrlAssertion);

    WebClient accessTokenService = WebClient.create(config.getServiceAccountTokenUri(),
            Arrays.asList(new OAuthJSONProvider(), new AccessTokenGrantWriter()));

    accessTokenService.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_JSON);

    return accessTokenService.post(grant, ClientAccessToken.class);
}
 
Example 3
Source File: HawkAccessToken.java    From cxf with Apache License 2.0 5 votes vote down vote up
public HawkAccessToken(Client client,
                      HmacAlgorithm macAlgo,
                      long lifetime) {
    this(client,
         macAlgo,
         OAuthUtils.generateRandomTokenKey(),
         lifetime,
         OAuthUtils.getIssuedAt());
}
 
Example 4
Source File: BearerAccessToken.java    From cxf with Apache License 2.0 5 votes vote down vote up
public BearerAccessToken(Client client,
                         long lifetime) {
    super(client,
          OAuthConstants.BEARER_TOKEN_TYPE,
          OAuthUtils.generateRandomTokenKey(),
          lifetime,
          OAuthUtils.getIssuedAt());
}
 
Example 5
Source File: RefreshToken.java    From cxf with Apache License 2.0 5 votes vote down vote up
public RefreshToken(Client client,
                    long lifetime) {
    super(client,
            OAuthConstants.REFRESH_TOKEN_TYPE,
            OAuthUtils.generateRandomTokenKey(),
            lifetime,
            OAuthUtils.getIssuedAt());
}
 
Example 6
Source File: EncryptingDataProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void createRefreshToken(ServerAccessToken token) {
    RefreshToken refreshToken = new RefreshToken(token.getClient(),
                                                 "refresh",
                                                 1200L,
                                                 OAuthUtils.getIssuedAt());

    String encryptedRefreshToken = ModelEncryptionSupport.encryptRefreshToken(refreshToken, key);
    token.setRefreshToken(encryptedRefreshToken);
}
 
Example 7
Source File: DefaultEncryptingCodeDataProvider.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected long getIssuedAt() {
    return OAuthUtils.getIssuedAt();
}
 
Example 8
Source File: AbstractAuthorizationCodeDataProvider.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected long getIssuedAt() {
    return OAuthUtils.getIssuedAt();
}
 
Example 9
Source File: ServerAuthorizationCodeGrant.java    From cxf with Apache License 2.0 4 votes vote down vote up
public ServerAuthorizationCodeGrant(Client client,
                                    long lifetime) {
    this(client, OAuthUtils.generateRandomTokenKey(), lifetime,
            OAuthUtils.getIssuedAt());
}
 
Example 10
Source File: ServerAccessToken.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected ServerAccessToken(Client client,
                            String tokenType,
                            String tokenKey,
                            long expiresIn) {
    this(client, tokenType, tokenKey, expiresIn, OAuthUtils.getIssuedAt());
}