Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load the google wallet service account from a key #503

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading