From 3f3c2412f840472d719cfa6340e890334826657f Mon Sep 17 00:00:00 2001 From: gsd Date: Thu, 10 Aug 2023 21:40:46 +0300 Subject: [PATCH] steam auth 2 --- .../controllers/auth/AuthSteamController.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/app/controllers/auth/AuthSteamController.java b/src/main/java/app/controllers/auth/AuthSteamController.java index 461f362..27b24c4 100644 --- a/src/main/java/app/controllers/auth/AuthSteamController.java +++ b/src/main/java/app/controllers/auth/AuthSteamController.java @@ -1,12 +1,16 @@ package app.controllers.auth; +import app.annotations.enums.AuthMethod; import app.annotations.exceptions.InvalidCookie; import app.annotations.exceptions.NeedCookie; +import app.annotations.interfaces.CheckWebAccess; +import app.services.db.DiscordAuthService; import app.services.steam.SteamSignIn; import app.services.steam.SteamWebApi; import app.utils.SaltedCookie; import app.utils.SteamIDConverter; import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -21,12 +25,14 @@ public class AuthSteamController { private SteamSignIn steamSignIn; private SaltedCookie saltedCookie; private SteamWebApi steamWebApi; + private DiscordAuthService discordAuthService; @Autowired - public AuthSteamController(SteamSignIn steamSignIn, SaltedCookie saltedCookie, SteamWebApi steamWebApi){ + public AuthSteamController(SteamSignIn steamSignIn, SaltedCookie saltedCookie, SteamWebApi steamWebApi, DiscordAuthService discordAuthService){ this.steamSignIn = steamSignIn; this.saltedCookie = saltedCookie; this.steamWebApi = steamWebApi; + this.discordAuthService = discordAuthService; } @GetMapping("login") @@ -86,4 +92,20 @@ public class AuthSteamController { return new ResponseEntity(steamWebApi.getSteamData(SteamIDConverter.getSteamID(steam64).steam64), HttpStatus.OK); } + + @GetMapping("steam/discord") + public ResponseEntity getDiscordID(@CookieValue(value = "steam64", defaultValue = "") String steam64, + @CookieValue(value = "steam64_secured", defaultValue = "") String steam64_secured) { + if (steam64.isEmpty() || steam64_secured.isEmpty()) { + throw new NeedCookie(); + } + + if (!saltedCookie.Validate(steam64, steam64_secured)) { + throw new InvalidCookie(); + } + + String discord_id = discordAuthService.getDiscordIDofSteamID(SteamIDConverter.getSteamID(steam64)); + if (discord_id != null) return new ResponseEntity(discord_id, HttpStatus.OK); + else return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } }