diff --git a/.gitignore b/.gitignore index 245bab2d..893d88ac 100644 --- a/.gitignore +++ b/.gitignore @@ -76,3 +76,4 @@ rebel.xml build/ bin/ .DS_Store +googleservicekey.json \ No newline at end of file diff --git a/config/application-devcontainer.yml b/config/application-devcontainer.yml index b8cf147b..cf5e847c 100644 --- a/config/application-devcontainer.yml +++ b/config/application-devcontainer.yml @@ -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 \ No newline at end of file diff --git a/config/application-test.yml b/config/application-test.yml index 5b455e12..dd37e9b3 100644 --- a/config/application-test.yml +++ b/config/application-test.yml @@ -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 \ No newline at end of file diff --git a/config/application.yml.example b/config/application.yml.example index 8cdc9304..5cf9b6cd 100644 --- a/config/application.yml.example +++ b/config/application.yml.example @@ -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 \ No newline at end of file diff --git a/src/main/java/ch/wisv/events/core/service/googlewallet/GoogleWalletServiceImpl.java b/src/main/java/ch/wisv/events/core/service/googlewallet/GoogleWalletServiceImpl.java index 6a54b317..23770aa5 100644 --- a/src/main/java/ch/wisv/events/core/service/googlewallet/GoogleWalletServiceImpl.java +++ b/src/main/java/ch/wisv/events/core/service/googlewallet/GoogleWalletServiceImpl.java @@ -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; @@ -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; @@ -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"; } }