Browse Source

steam auth 2

master
gsd 2 years ago
parent
commit
3f3c2412f8
  1. 24
      src/main/java/app/controllers/auth/AuthSteamController.java

24
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<String> 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);
}
}

Loading…
Cancel
Save