Skip to content

Commit

Permalink
Merge pull request #503 from WISVCH/googlewalletserviceaccount
Browse files Browse the repository at this point in the history
Load the google wallet service account from a key
  • Loading branch information
dsluijk authored Aug 14, 2024
2 parents a74eed0 + dd132ee commit 4329472
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ rebel.xml
build/
bin/
.DS_Store
googleservicekey.json
1 change: 1 addition & 0 deletions config/application-devcontainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ links:
passes: https://ch.tudelft.nl/passes

googleWallet:
serviceKeyPath: ./googleservicekey.json
issuerId: 3388000000022297569
origin: http://localhost:8080
baseUrl: https://ch.tudelft.nl/events
1 change: 1 addition & 0 deletions config/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ links:
passes: passes

googleWallet:
serviceKeyPath: ./googleservicekey.json
issuerId: 3388000000022297569
origin: https://ch.tudelft.nl/events
baseUrl: https://ch.tudelft.nl/events
1 change: 1 addition & 0 deletions config/application.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ links:
passes: https://ch.tudelft.nl/passes

googleWallet:
serviceKeyPath: ./googleservicekey.json
issuerId: 3388000000022297569
origin: https://ch.tudelft.nl/events
baseUrl: https://ch.tudelft.nl/events
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.google.api.services.walletobjects.WalletobjectsScopes;
import com.google.api.services.walletobjects.model.*;
import com.google.auth.oauth2.ServiceAccountCredentials;

import jakarta.validation.constraints.NotNull;

import java.io.FileInputStream;
import java.io.IOException;
import java.security.interfaces.RSAPrivateKey;
import java.time.Instant;
Expand All @@ -31,6 +31,10 @@ public class GoogleWalletServiceImpl implements GoogleWalletService {
/** Service account credentials for Google Wallet APIs. */
public static ServiceAccountCredentials credentials;

@Value("${googleWallet.serviceKeyPath}")
@NotNull
private String serviceKeyPath;

@Value("${googleWallet.issuerId}")
@NotNull
private String issuerId;
Expand All @@ -57,12 +61,10 @@ public class GoogleWalletServiceImpl implements GoogleWalletService {
public String getPass(Ticket ticket) throws TicketPassFailedException {
if (credentials == null) {
try {
credentials = (ServiceAccountCredentials) ServiceAccountCredentials
.getApplicationDefault()
.createScoped(List.of(WalletobjectsScopes.WALLET_OBJECT_ISSUER));
credentials.refresh();
credentials = ServiceAccountCredentials.fromStream(new FileInputStream(this.serviceKeyPath));
} catch (IOException e) {
System.out.println("WARN: Failed to authenticate with Google");
System.out.println("WARN: Failed to parse service account");
System.out.println(e);
return "https://pay.google.com/gp/v/save/FAILED";
}
}
Expand Down

0 comments on commit 4329472

Please sign in to comment.