mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-06-09 07:18:22 +00:00
debug discord login (6x)
This commit is contained in:
parent
25b835456e
commit
a1e44c3bb1
@ -21,6 +21,7 @@ import io.ktor.server.sessions.*
|
||||
import io.ktor.server.websocket.*
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.slf4j.LoggerFactory
|
||||
import space.mori.chzzk_bot.common.services.UserService
|
||||
import space.mori.chzzk_bot.webserver.routes.*
|
||||
import java.time.Duration
|
||||
@ -33,6 +34,8 @@ const val naverMeAPIURL = "https://openapi.naver.com/v1/nid/me"
|
||||
|
||||
val redirects = mutableMapOf<String, String>()
|
||||
|
||||
val logger = LoggerFactory.getLogger("ktorMain")
|
||||
|
||||
val server = embeddedServer(Netty, port = 8080, ) {
|
||||
install(WebSockets) {
|
||||
pingPeriod = Duration.ofSeconds(15)
|
||||
@ -73,13 +76,14 @@ val server = embeddedServer(Netty, port = 8080, ) {
|
||||
client = applicationHttpClient
|
||||
}
|
||||
oauth("auth-oauth-discord") {
|
||||
urlProvider = { "${dotenv["HOST"]}/auth/discord/callback" }
|
||||
urlProvider = { "${dotenv["HOST"]}/auth/callback/discord" }
|
||||
providerLookup = { OAuthServerSettings.OAuth2ServerSettings(
|
||||
name = "discord",
|
||||
authorizeUrl = "https://discord.com/oauth2/authorize",
|
||||
accessTokenUrl = "https://discord.com/api/oauth2/token",
|
||||
clientId = dotenv["DISCORD_CLIENT_ID"],
|
||||
clientSecret = dotenv["DISCORD_CLIENT_SECRET"],
|
||||
requestMethod = HttpMethod.Post,
|
||||
defaultScopes = listOf(),
|
||||
extraAuthParameters = listOf(
|
||||
Pair("permissions", "826781355072"),
|
||||
@ -103,16 +107,22 @@ val server = embeddedServer(Netty, port = 8080, ) {
|
||||
get("/login/discord") {
|
||||
|
||||
}
|
||||
get("/discord/callback") {
|
||||
get("/callback/discord") {
|
||||
println("CALLBACK")
|
||||
try {
|
||||
val principal = call.principal<OAuthAccessTokenResponse.OAuth2>()
|
||||
val session = call.sessions.get<UserSession>()
|
||||
val user = session?.id?.let { UserService.getUserWithNaverId(it) }
|
||||
|
||||
if(principal != null && session != null && user != null) {
|
||||
try {
|
||||
val accessToken = principal.accessToken
|
||||
val userInfo = getDiscordUser(accessToken)
|
||||
val guilds = getUserGuilds(accessToken)
|
||||
|
||||
println(userInfo)
|
||||
println(guilds)
|
||||
|
||||
userInfo?.user?.id?.toLong()?.let { id -> UserService.updateUser(user, id) }
|
||||
|
||||
call.sessions.set(UserSession(
|
||||
@ -127,15 +137,21 @@ val server = embeddedServer(Netty, port = 8080, ) {
|
||||
}
|
||||
|
||||
call.respondRedirect(getFrontendURL(""))
|
||||
} catch(e: Exception) {
|
||||
logger.debug(e.toString())
|
||||
}
|
||||
} else {
|
||||
call.respondRedirect(getFrontendURL(""))
|
||||
}
|
||||
} catch(e: Exception) {
|
||||
println(e.stackTrace)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// naver login
|
||||
authenticate("auth-oauth-naver") {
|
||||
get("/login/discord") {
|
||||
get("/login") {
|
||||
|
||||
}
|
||||
get("/callback") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user