Skip to content

Commit

Permalink
🗑 Deprecate not needed IdTokenVerifierMock Traverse requirements.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwojnowski committed Nov 29, 2023
1 parent b8416dc commit 9998333
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,42 @@ object IdTokenVerifierMock {

}

@deprecated("Use version with explicit client ID")
def constSubject[F[_]: Applicative: Traverse: Clock](subject: IdTokenClaims.Subject): IdTokenVerifier[F] =
constSubjectEither[F](Right(subject))
constSubject[F](subject, ClientId("https://example.com"))

def constSubjectEither[F[_]: Applicative: Traverse: Clock](errorOrSubject: Either[IdTokenVerifier.Error, IdTokenClaims.Subject])
def constSubject[F[_]: Applicative: Clock](subject: IdTokenClaims.Subject, clientId: ClientId = ClientId("https://example.com"))
: IdTokenVerifier[F] =
constSubjectPF[F]((_: String) => errorOrSubject)
constSubjectEither[F](Right(subject), clientId)

@deprecated("Use version with explicit client ID")
def constSubjectEither[F[_]: Applicative: Traverse: Clock](errorOrSubject: Either[IdTokenVerifier.Error, IdTokenClaims.Subject])
: IdTokenVerifier[F] = constSubjectEither[F](errorOrSubject, ClientId("https://example.com"))

def constSubjectEither[F[_]: Applicative: Clock](
errorOrSubject: Either[IdTokenVerifier.Error, IdTokenClaims.Subject],
clientId: ClientId = ClientId("https://example.com")
): IdTokenVerifier[F] =
constSubjectPF[F]((_: String) => errorOrSubject, clientId)

@deprecated("Use version with explicit client ID")
def constSubjectPF[F[_]: Applicative: Traverse: Clock](
rawTokenToSubjectPF: PartialFunction[String, Either[IdTokenVerifier.Error, IdTokenClaims.Subject]]
): IdTokenVerifier[F] =
constStandardClaimsEitherPF(
constSubjectPF[F](rawTokenToSubjectPF, ClientId("https://example.com"))

def constSubjectPF[F[_]: Applicative: Clock](
rawTokenToSubjectPF: PartialFunction[String, Either[IdTokenVerifier.Error, IdTokenClaims.Subject]],
clientId: ClientId = ClientId("https://example.com")
): IdTokenVerifier[F] =
constClaimsEitherPF(
rawTokenToSubjectPF.map { errorOrSubject =>
Applicative[F].map(Clock[F].realTimeInstant) { now =>
errorOrSubject.map(subject =>
IdTokenClaims(
Issuer("https://example.com"),
subject,
NonEmptySet.of(Audience("https://example.com")),
NonEmptySet.of(Audience(clientId.value)),
expiration = now.plusSeconds(600),
issuedAt = now
)
Expand All @@ -112,14 +130,26 @@ object IdTokenVerifierMock {
}
)

def constStandardClaims[F[_]: Applicative: Traverse](claims: IdTokenClaims): IdTokenVerifier[F] = constStandardClaimsEither(Right(claims))
@deprecated("Use constClaims", "0.12.2")
def constStandardClaims[F[_]: Applicative: Traverse](claims: IdTokenClaims): IdTokenVerifier[F] = constClaims(claims)

@deprecated("Use constClaimsEither", "0.12.2")
def constStandardClaimsEither[F[_]: Applicative: Traverse](claimsEither: Either[IdTokenVerifier.Error, IdTokenClaims])
: IdTokenVerifier[F] =
constStandardClaimsEitherPF[F](_ => claimsEither.pure[F])
constClaimsEither(claimsEither)

@deprecated("Use constClaimsEitherPF", "0.12.2")
def constStandardClaimsEitherPF[F[_]: Applicative: Traverse](
rawTokenToClaimsPF: PartialFunction[String, F[Either[IdTokenVerifier.Error, IdTokenClaims]]]
): IdTokenVerifier[F] = constClaimsEitherPF(rawTokenToClaimsPF)

def constClaims[F[_]: Applicative](claims: IdTokenClaims): IdTokenVerifier[F] = constClaimsEither(Right(claims))

def constClaimsEither[F[_]: Applicative](claimsEither: Either[IdTokenVerifier.Error, IdTokenClaims]): IdTokenVerifier[F] =
constClaimsEitherPF[F](_ => claimsEither.pure[F])

def constClaimsEitherPF[F[_]: Applicative](
rawTokenToClaimsPF: PartialFunction[String, F[Either[IdTokenVerifier.Error, IdTokenClaims]]]
): IdTokenVerifier[F] = new IdTokenVerifier[F] {

override def verifyAndDecode(rawToken: String): F[Either[IdTokenVerifier.Error, IdTokenClaims]] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import munit.FunSuite
import java.time.Instant
import CirceJsonSupport._
import cats.data.NonEmptySet
import cats.data.NonEmptySetImpl
import cats.effect.Clock
import me.wojnowski.oidc4s.IdTokenClaims.Audience
import me.wojnowski.oidc4s.IdTokenClaims.Subject
Expand Down

0 comments on commit 9998333

Please sign in to comment.