I need to access Google's BigQuery REST Api Endpoints with Service Account using Http client library. So, I tried the code provided in the article Using OAuth 2.0 for Server to Server Applications
It gives me the compilation error in the below line.
Algorithm.RSA256(null, privateKey)
Code below:
GoogleCredential credential = GoogleCredential
.fromStream(new FileInputStream("service_account.json"));
PrivateKey privateKey = credential.getServiceAccountPrivateKey();
String privateKeyId = credential.getServiceAccountPrivateKeyId();
try {
Algorithm algorithm = Algorithm.RSA256(null, privateKey);
String signedJwt = JWT.create().withKeyId(privateKeyId)
.withIssuer("123456-compute@developer.gserviceaccount.com")
.withSubject("123456-compute@developer.gserviceaccount.com")
.withAudience("https://firestore.googleapis.com/google.firestore.v1beta1.Firestore")
.withIssuedAt(new Date(now)).withExpiresAt(new Date(now + 3600 * 1000L)).sign(algorithm);
} catch (Exception e) {
e.printStackTrace();
}
Note: Algorithm.RSA256() accept java.security.interfaces.RSAPrivateKey whereas Google Api returns java.security.PrivateKey
Could anyone help me in this?