Skip to content

Commit

Permalink
Fix oauth persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddenton committed Aug 25, 2024
1 parent 2e4d273 commit 8cac032
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions oauth/src/main/kotlin/com/example/InMemoryOAuthPersistence.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import org.http4k.core.cookie.invalidateCookie
import org.http4k.security.AccessToken
import org.http4k.security.CrossSiteRequestForgeryToken
import org.http4k.security.Nonce
import org.http4k.security.OAuthPersistence
import org.http4k.security.OAuthCallbackError
import org.http4k.security.OAuthPersistence
import org.http4k.security.PkceChallengeAndVerifier
import org.http4k.security.openid.IdToken
import java.time.Clock
import java.time.Duration
import java.time.LocalDateTime
import java.util.UUID

/**
Expand All @@ -34,16 +33,23 @@ class InMemoryOAuthPersistence(private val clock: Clock) : OAuthPersistence {
override fun retrieveOriginalUri(request: Request): Uri? =
request.cookie(originalUriName)?.value?.let(Uri::of)

override fun retrievePkce(request: Request) = null

override fun retrieveToken(request: Request) = (tryBearerToken(request)
?: tryCookieToken(request))
?.takeIf { it.value.startsWith("ACCESS_TOKEN") }

override fun assignCsrf(redirect: Response, csrf: CrossSiteRequestForgeryToken) = redirect.cookie(expiring(csrfName, csrf.value))
override fun assignCsrf(redirect: Response, csrf: CrossSiteRequestForgeryToken) =
redirect.cookie(expiring(csrfName, csrf.value))

override fun assignNonce(redirect: Response, nonce: Nonce): Response = redirect
override fun assignOriginalUri(redirect: Response, originalUri: Uri): Response =
redirect.cookie(expiring(originalUriName, originalUri.toString()))

override fun assignPkce(redirect: Response, pkce: PkceChallengeAndVerifier): Response {
TODO("Not yet implemented")
}

override fun assignToken(request: Request, redirect: Response, accessToken: AccessToken, idToken: IdToken?) =
UUID.randomUUID().let {
cookieSwappableTokens[it.toString()] = accessToken
Expand Down

0 comments on commit 8cac032

Please sign in to comment.