Skip to content

Commit

Permalink
CAM is now free of using any deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
NovaFox161 committed Mar 21, 2024
1 parent 74ee20b commit 4e37215
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Expand Up @@ -4,20 +4,21 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import kotlinx.coroutines.reactor.awaitSingle
import okhttp3.FormBody
import okhttp3.OkHttpClient
import okhttp3.Request
import org.dreamexposure.discal.cam.json.discord.AccessTokenResponse
import org.dreamexposure.discal.cam.json.discord.AuthorizationInfo
import org.dreamexposure.discal.core.config.Config
import org.dreamexposure.discal.core.exceptions.AuthenticationException
import org.dreamexposure.discal.core.utils.GlobalVal
import org.dreamexposure.discal.core.utils.GlobalVal.HTTP_CLIENT
import org.springframework.stereotype.Component
import reactor.core.publisher.Mono
import reactor.core.scheduler.Schedulers

@Component
class DiscordOauthHandler(
private val objectMapper: ObjectMapper,
private val httpClient: OkHttpClient,
) {
private val cdnUrl = "https://cdn.discordapp.com"
private val redirectUrl = Config.URL_DISCORD_REDIRECT.getString()
Expand All @@ -38,7 +39,7 @@ class DiscordOauthHandler(
.header("Content-Type", "application/x-www-form-urlencoded")
.build()

val response = Mono.fromCallable(HTTP_CLIENT.newCall(tokenExchangeRequest)::execute)
val response = Mono.fromCallable(httpClient.newCall(tokenExchangeRequest)::execute)
.subscribeOn(Schedulers.boundedElastic())
.awaitSingle()

Expand Down Expand Up @@ -66,7 +67,7 @@ class DiscordOauthHandler(
.header("Content-Type", "application/x-www-form-urlencoded")
.build()

val response = Mono.fromCallable(HTTP_CLIENT.newCall(tokenExchangeRequest)::execute)
val response = Mono.fromCallable(httpClient.newCall(tokenExchangeRequest)::execute)
.subscribeOn(Schedulers.boundedElastic())
.awaitSingle()

Expand All @@ -88,7 +89,7 @@ class DiscordOauthHandler(
.header("Authorization", "Bearer $accessToken")
.build()

val response = Mono.fromCallable(HTTP_CLIENT.newCall(request)::execute)
val response = Mono.fromCallable(httpClient.newCall(request)::execute)
.subscribeOn(Schedulers.boundedElastic())
.awaitSingle()

Expand Down
Expand Up @@ -6,6 +6,7 @@ import com.google.api.client.http.HttpStatusCodes.STATUS_CODE_BAD_REQUEST
import com.google.api.client.http.HttpStatusCodes.STATUS_CODE_OK
import kotlinx.coroutines.reactor.awaitSingle
import okhttp3.FormBody
import okhttp3.OkHttpClient
import okhttp3.Request
import org.dreamexposure.discal.cam.json.google.ErrorData
import org.dreamexposure.discal.cam.json.google.RefreshData
Expand All @@ -20,7 +21,6 @@ import org.dreamexposure.discal.core.logger.LOGGER
import org.dreamexposure.discal.core.`object`.network.discal.CredentialData
import org.dreamexposure.discal.core.`object`.new.Calendar
import org.dreamexposure.discal.core.utils.GlobalVal.DEFAULT
import org.dreamexposure.discal.core.utils.GlobalVal.HTTP_CLIENT
import org.springframework.stereotype.Component
import reactor.core.publisher.Mono
import reactor.core.scheduler.Schedulers
Expand All @@ -32,6 +32,7 @@ class GoogleAuth(
private val credentialService: CredentialService,
private val calendarService: CalendarService,
private val objectMapper: ObjectMapper,
private val httpClient: OkHttpClient,
) {

suspend fun requestNewAccessToken(calendar: Calendar): CredentialData? {
Expand Down Expand Up @@ -79,7 +80,7 @@ class GoogleAuth(
.build()


val response = Mono.fromCallable(HTTP_CLIENT.newCall(request)::execute)
val response = Mono.fromCallable(httpClient.newCall(request)::execute)
.subscribeOn(Schedulers.boundedElastic())
.awaitSingle()

Expand Down

0 comments on commit 4e37215

Please sign in to comment.