From 4a7e9ccd0c7ec3abd19900b4670fbaf5f7715742 Mon Sep 17 00:00:00 2001 From: gsd Date: Thu, 10 Aug 2023 20:44:04 +0300 Subject: [PATCH] steam auth 1 --- .../auth/AuthDiscordController.java | 4 +-- .../controllers/auth/AuthSteamController.java | 27 +++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/main/java/app/controllers/auth/AuthDiscordController.java b/src/main/java/app/controllers/auth/AuthDiscordController.java index ab993b6..227ce6c 100644 --- a/src/main/java/app/controllers/auth/AuthDiscordController.java +++ b/src/main/java/app/controllers/auth/AuthDiscordController.java @@ -49,7 +49,7 @@ public class AuthDiscordController { cookie_discord.setPath("/"); response.addCookie(cookie_discord); return ResponseEntity.status(HttpStatus.FOUND). - header("Location", "/authentication_discord") + header("Location", "/authentication_discord.html") .build(); } @@ -85,7 +85,7 @@ public class AuthDiscordController { response.addCookie(cookie_discord); return ResponseEntity.status(HttpStatus.FOUND). - header("Location", "/authentication_discord") + header("Location", "/authentication_discord.html") .build(); } diff --git a/src/main/java/app/controllers/auth/AuthSteamController.java b/src/main/java/app/controllers/auth/AuthSteamController.java index 5d28b8e..461f362 100644 --- a/src/main/java/app/controllers/auth/AuthSteamController.java +++ b/src/main/java/app/controllers/auth/AuthSteamController.java @@ -1,16 +1,17 @@ package app.controllers.auth; +import app.annotations.exceptions.InvalidCookie; +import app.annotations.exceptions.NeedCookie; 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.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.Map; @@ -19,11 +20,13 @@ import java.util.Map; public class AuthSteamController { private SteamSignIn steamSignIn; private SaltedCookie saltedCookie; + private SteamWebApi steamWebApi; @Autowired - public AuthSteamController(SteamSignIn steamSignIn, SaltedCookie saltedCookie){ + public AuthSteamController(SteamSignIn steamSignIn, SaltedCookie saltedCookie, SteamWebApi steamWebApi){ this.steamSignIn = steamSignIn; this.saltedCookie = saltedCookie; + this.steamWebApi = steamWebApi; } @GetMapping("login") @@ -69,4 +72,18 @@ public class AuthSteamController { header("Location", "/") .build(); } + + @GetMapping("steam") + public ResponseEntity aboutMe(@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(); + } + + return new ResponseEntity(steamWebApi.getSteamData(SteamIDConverter.getSteamID(steam64).steam64), HttpStatus.OK); + } }