From 1ec8248c6fdff23fd6dafde50697113a0318999e Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 7 Aug 2024 05:19:24 +0100 Subject: [PATCH] IMPL BASIC AUTH INTO MOD AND BACKEND --- .../java/cc/fascinated/common/IPUtils.java | 4 ++ .../cc/fascinated/common/StringUtils.java | 4 ++ .../cc/fascinated/config/RedisConfig.java | 4 ++ .../controller/AuthenticationController.java | 4 ++ .../cc/fascinated/log/TransactionLogger.java | 4 ++ .../cc/fascinated/model/auth/AuthToken.java | 36 ++++++++++++ .../fascinated/model/auth/LoginRequest.java | 4 ++ .../ScoreSaberAccountToken.java | 0 .../ScoreSaberLeaderboardPageToken.java | 0 .../ScoreSaberLeaderboardToken.java | 0 .../ScoreSaberPageMetadataToken.java | 0 .../ScoreSaberPlayerScoreToken.java | 0 .../ScoreSaberScoreToken.java | 0 .../ScoreSaberScoresPageToken.java | 0 .../ScoreSaberWebsocketDataToken.java | 0 .../SteamAuthenticateUserTicketToken.java | 55 +++++++++++++++++++ .../{ => mongo}/CounterRepository.java | 0 .../{ => mongo}/ScoreRepository.java | 0 .../ScoreSaberLeaderboardRepository.java | 2 +- .../{ => mongo}/UserRepository.java | 0 .../repository/redis/AuthTokenRepository.java | 4 ++ .../cc/fascinated/services/SteamService.java | 4 ++ 22 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 API/src/main/java/cc/fascinated/common/IPUtils.java create mode 100644 API/src/main/java/cc/fascinated/common/StringUtils.java create mode 100644 API/src/main/java/cc/fascinated/config/RedisConfig.java create mode 100644 API/src/main/java/cc/fascinated/controller/AuthenticationController.java create mode 100644 API/src/main/java/cc/fascinated/log/TransactionLogger.java create mode 100644 API/src/main/java/cc/fascinated/model/auth/AuthToken.java create mode 100644 API/src/main/java/cc/fascinated/model/auth/LoginRequest.java rename API/src/main/java/cc/fascinated/model/token/{ => scoresaber}/ScoreSaberAccountToken.java (100%) rename API/src/main/java/cc/fascinated/model/token/{ => scoresaber}/ScoreSaberLeaderboardPageToken.java (100%) rename API/src/main/java/cc/fascinated/model/token/{ => scoresaber}/ScoreSaberLeaderboardToken.java (100%) rename API/src/main/java/cc/fascinated/model/token/{ => scoresaber}/ScoreSaberPageMetadataToken.java (100%) rename API/src/main/java/cc/fascinated/model/token/{ => scoresaber}/ScoreSaberPlayerScoreToken.java (100%) rename API/src/main/java/cc/fascinated/model/token/{ => scoresaber}/ScoreSaberScoreToken.java (100%) rename API/src/main/java/cc/fascinated/model/token/{ => scoresaber}/ScoreSaberScoresPageToken.java (100%) rename API/src/main/java/cc/fascinated/model/token/{ => scoresaber}/ScoreSaberWebsocketDataToken.java (100%) create mode 100644 API/src/main/java/cc/fascinated/model/token/steam/SteamAuthenticateUserTicketToken.java rename API/src/main/java/cc/fascinated/repository/{ => mongo}/CounterRepository.java (100%) rename API/src/main/java/cc/fascinated/repository/{ => mongo}/ScoreRepository.java (100%) rename API/src/main/java/cc/fascinated/repository/{ => mongo}/ScoreSaberLeaderboardRepository.java (78%) rename API/src/main/java/cc/fascinated/repository/{ => mongo}/UserRepository.java (100%) create mode 100644 API/src/main/java/cc/fascinated/repository/redis/AuthTokenRepository.java create mode 100644 API/src/main/java/cc/fascinated/services/SteamService.java diff --git a/API/src/main/java/cc/fascinated/common/IPUtils.java b/API/src/main/java/cc/fascinated/common/IPUtils.java new file mode 100644 index 0000000..002f2e7 --- /dev/null +++ b/API/src/main/java/cc/fascinated/common/IPUtils.java @@ -0,0 +1,4 @@ +package cc.fascinated.common;/** + * @author Fascinated (fascinated7) + */public class IPUtils { +} diff --git a/API/src/main/java/cc/fascinated/common/StringUtils.java b/API/src/main/java/cc/fascinated/common/StringUtils.java new file mode 100644 index 0000000..81cf42d --- /dev/null +++ b/API/src/main/java/cc/fascinated/common/StringUtils.java @@ -0,0 +1,4 @@ +package cc.fascinated.common;/** + * @author Fascinated (fascinated7) + */public class StringUtils { +} diff --git a/API/src/main/java/cc/fascinated/config/RedisConfig.java b/API/src/main/java/cc/fascinated/config/RedisConfig.java new file mode 100644 index 0000000..6ee52fa --- /dev/null +++ b/API/src/main/java/cc/fascinated/config/RedisConfig.java @@ -0,0 +1,4 @@ +package cc.fascinated.config;/** + * @author Fascinated (fascinated7) + */public class RedisConfig { +} diff --git a/API/src/main/java/cc/fascinated/controller/AuthenticationController.java b/API/src/main/java/cc/fascinated/controller/AuthenticationController.java new file mode 100644 index 0000000..529ea55 --- /dev/null +++ b/API/src/main/java/cc/fascinated/controller/AuthenticationController.java @@ -0,0 +1,4 @@ +package cc.fascinated.controller;/** + * @author Fascinated (fascinated7) + */public class AuthenticationController { +} diff --git a/API/src/main/java/cc/fascinated/log/TransactionLogger.java b/API/src/main/java/cc/fascinated/log/TransactionLogger.java new file mode 100644 index 0000000..45eb949 --- /dev/null +++ b/API/src/main/java/cc/fascinated/log/TransactionLogger.java @@ -0,0 +1,4 @@ +package cc.fascinated.log;/** + * @author Fascinated (fascinated7) + */public class TransactionLogger { +} diff --git a/API/src/main/java/cc/fascinated/model/auth/AuthToken.java b/API/src/main/java/cc/fascinated/model/auth/AuthToken.java new file mode 100644 index 0000000..350b303 --- /dev/null +++ b/API/src/main/java/cc/fascinated/model/auth/AuthToken.java @@ -0,0 +1,36 @@ +package cc.fascinated.model.auth; + +import cc.fascinated.common.StringUtils; +import cc.fascinated.model.token.steam.SteamAuthenticateUserTicketToken; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @author Fascinated (fascinated7) + */ +@AllArgsConstructor +@Getter +public class SteamAuthToken { + /** + * The steam id of the user. + */ + private final String steamId; + + /** + * The auth token of the user. + */ + private final String authToken; + + /** + * Gets the SteamProfile from an auth token. + * + * @param token The auth token. + * @return The SteamProfile. + */ + public static SteamAuthToken getFromAuthToken(SteamAuthenticateUserTicketToken token) { + return new SteamAuthToken( + token.getResponse().getParams().getSteamId(), + StringUtils.randomString(32) + ); + } +} diff --git a/API/src/main/java/cc/fascinated/model/auth/LoginRequest.java b/API/src/main/java/cc/fascinated/model/auth/LoginRequest.java new file mode 100644 index 0000000..c933ecd --- /dev/null +++ b/API/src/main/java/cc/fascinated/model/auth/LoginRequest.java @@ -0,0 +1,4 @@ +package cc.fascinated.model.auth;/** + * @author Fascinated (fascinated7) + */public class LoginRequest { +} diff --git a/API/src/main/java/cc/fascinated/model/token/ScoreSaberAccountToken.java b/API/src/main/java/cc/fascinated/model/token/scoresaber/ScoreSaberAccountToken.java similarity index 100% rename from API/src/main/java/cc/fascinated/model/token/ScoreSaberAccountToken.java rename to API/src/main/java/cc/fascinated/model/token/scoresaber/ScoreSaberAccountToken.java diff --git a/API/src/main/java/cc/fascinated/model/token/ScoreSaberLeaderboardPageToken.java b/API/src/main/java/cc/fascinated/model/token/scoresaber/ScoreSaberLeaderboardPageToken.java similarity index 100% rename from API/src/main/java/cc/fascinated/model/token/ScoreSaberLeaderboardPageToken.java rename to API/src/main/java/cc/fascinated/model/token/scoresaber/ScoreSaberLeaderboardPageToken.java diff --git a/API/src/main/java/cc/fascinated/model/token/ScoreSaberLeaderboardToken.java b/API/src/main/java/cc/fascinated/model/token/scoresaber/ScoreSaberLeaderboardToken.java similarity index 100% rename from API/src/main/java/cc/fascinated/model/token/ScoreSaberLeaderboardToken.java rename to API/src/main/java/cc/fascinated/model/token/scoresaber/ScoreSaberLeaderboardToken.java diff --git a/API/src/main/java/cc/fascinated/model/token/ScoreSaberPageMetadataToken.java b/API/src/main/java/cc/fascinated/model/token/scoresaber/ScoreSaberPageMetadataToken.java similarity index 100% rename from API/src/main/java/cc/fascinated/model/token/ScoreSaberPageMetadataToken.java rename to API/src/main/java/cc/fascinated/model/token/scoresaber/ScoreSaberPageMetadataToken.java diff --git a/API/src/main/java/cc/fascinated/model/token/ScoreSaberPlayerScoreToken.java b/API/src/main/java/cc/fascinated/model/token/scoresaber/ScoreSaberPlayerScoreToken.java similarity index 100% rename from API/src/main/java/cc/fascinated/model/token/ScoreSaberPlayerScoreToken.java rename to API/src/main/java/cc/fascinated/model/token/scoresaber/ScoreSaberPlayerScoreToken.java diff --git a/API/src/main/java/cc/fascinated/model/token/ScoreSaberScoreToken.java b/API/src/main/java/cc/fascinated/model/token/scoresaber/ScoreSaberScoreToken.java similarity index 100% rename from API/src/main/java/cc/fascinated/model/token/ScoreSaberScoreToken.java rename to API/src/main/java/cc/fascinated/model/token/scoresaber/ScoreSaberScoreToken.java diff --git a/API/src/main/java/cc/fascinated/model/token/ScoreSaberScoresPageToken.java b/API/src/main/java/cc/fascinated/model/token/scoresaber/ScoreSaberScoresPageToken.java similarity index 100% rename from API/src/main/java/cc/fascinated/model/token/ScoreSaberScoresPageToken.java rename to API/src/main/java/cc/fascinated/model/token/scoresaber/ScoreSaberScoresPageToken.java diff --git a/API/src/main/java/cc/fascinated/model/token/ScoreSaberWebsocketDataToken.java b/API/src/main/java/cc/fascinated/model/token/scoresaber/ScoreSaberWebsocketDataToken.java similarity index 100% rename from API/src/main/java/cc/fascinated/model/token/ScoreSaberWebsocketDataToken.java rename to API/src/main/java/cc/fascinated/model/token/scoresaber/ScoreSaberWebsocketDataToken.java diff --git a/API/src/main/java/cc/fascinated/model/token/steam/SteamAuthenticateUserTicketToken.java b/API/src/main/java/cc/fascinated/model/token/steam/SteamAuthenticateUserTicketToken.java new file mode 100644 index 0000000..a48817b --- /dev/null +++ b/API/src/main/java/cc/fascinated/model/token/steam/SteamAuthenticateUserTicketToken.java @@ -0,0 +1,55 @@ +package cc.fascinated.model.token.steam.token; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; + +/** + * @author Fascinated (fascinated7) + */ +@Getter +public class SteamAuthenticateUserTicketToken { + /** + * The response from the Steam API. + */ + private Response response; + + @Getter + public static class Response { + /** + * The params of the response. + */ + private Params params; + + @Getter + public static class Params { + /** + * The result of the request. + */ + private String result; + + /** + * The steam id of the user. + */ + @JsonProperty("steamid") + private String steamId; + + /** + * The owner steam id of the user. + */ + @JsonProperty("ownersteamid") + private String ownerSteamId; + + /** + * The vac banned status of the user. + */ + @JsonProperty("vacbanned") + private boolean vacBanned; + + /** + * The publisher banned status of the user. + */ + @JsonProperty("publisherbanned") + private boolean publisherBanned; + } + } +} diff --git a/API/src/main/java/cc/fascinated/repository/CounterRepository.java b/API/src/main/java/cc/fascinated/repository/mongo/CounterRepository.java similarity index 100% rename from API/src/main/java/cc/fascinated/repository/CounterRepository.java rename to API/src/main/java/cc/fascinated/repository/mongo/CounterRepository.java diff --git a/API/src/main/java/cc/fascinated/repository/ScoreRepository.java b/API/src/main/java/cc/fascinated/repository/mongo/ScoreRepository.java similarity index 100% rename from API/src/main/java/cc/fascinated/repository/ScoreRepository.java rename to API/src/main/java/cc/fascinated/repository/mongo/ScoreRepository.java diff --git a/API/src/main/java/cc/fascinated/repository/ScoreSaberLeaderboardRepository.java b/API/src/main/java/cc/fascinated/repository/mongo/ScoreSaberLeaderboardRepository.java similarity index 78% rename from API/src/main/java/cc/fascinated/repository/ScoreSaberLeaderboardRepository.java rename to API/src/main/java/cc/fascinated/repository/mongo/ScoreSaberLeaderboardRepository.java index 22ad72f..bbe20ba 100644 --- a/API/src/main/java/cc/fascinated/repository/ScoreSaberLeaderboardRepository.java +++ b/API/src/main/java/cc/fascinated/repository/mongo/ScoreSaberLeaderboardRepository.java @@ -1,6 +1,6 @@ package cc.fascinated.repository; -import cc.fascinated.model.token.ScoreSaberLeaderboardToken; +import cc.fascinated.model.token.scoresaber.ScoreSaberLeaderboardToken; import org.springframework.data.mongodb.repository.MongoRepository; /** diff --git a/API/src/main/java/cc/fascinated/repository/UserRepository.java b/API/src/main/java/cc/fascinated/repository/mongo/UserRepository.java similarity index 100% rename from API/src/main/java/cc/fascinated/repository/UserRepository.java rename to API/src/main/java/cc/fascinated/repository/mongo/UserRepository.java diff --git a/API/src/main/java/cc/fascinated/repository/redis/AuthTokenRepository.java b/API/src/main/java/cc/fascinated/repository/redis/AuthTokenRepository.java new file mode 100644 index 0000000..868f3f9 --- /dev/null +++ b/API/src/main/java/cc/fascinated/repository/redis/AuthTokenRepository.java @@ -0,0 +1,4 @@ +package cc.fascinated.repository.mongo.redis;/** + * @author Fascinated (fascinated7) + */public class AuthTokenRepository { +} diff --git a/API/src/main/java/cc/fascinated/services/SteamService.java b/API/src/main/java/cc/fascinated/services/SteamService.java new file mode 100644 index 0000000..2dc2dd4 --- /dev/null +++ b/API/src/main/java/cc/fascinated/services/SteamService.java @@ -0,0 +1,4 @@ +package cc.fascinated.services;/** + * @author Fascinated (fascinated7) + */public class SteamService { +}