Pac4jAuthenticationAdapter

works.iterative.server.http.impl.pac4j.Pac4jAuthenticationAdapter
object Pac4jAuthenticationAdapter extends AuthenticationService

Adapter that bridges Pac4J authentication to ZIO AuthenticationService.

This adapter:

  • Maps Pac4J CommonProfile (Java) to BasicProfile (Scala/ZIO)
  • Handles null values defensively with Option
  • Stores user context in FiberRef for request-scoped authentication
  • Extracts roles from Pac4J profile attributes

Example usage:

// After Pac4J successful authentication with CommonProfile
val profile: CommonProfile = ... // from Pac4J
val token = AccessToken("oauth-token-123")

for
 adapter <- ZIO.service[AuthenticationService]
 basicProfile = Pac4jAuthenticationAdapter.mapProfile(profile)
 _ <- adapter.loggedIn(token, basicProfile)
 currentUser <- adapter.currentUserInfo
yield currentUser // Some(AuthedUserInfo(...))

Attributes

Graph
Supertypes
trait AuthenticationService
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

override def loggedIn(token: AccessToken, profile: BasicProfile): UIO[Unit]

Attributes

Definition Classes
AuthenticationService
def mapProfile(profile: CommonProfile): BasicProfile

Maps a Pac4J CommonProfile to our BasicProfile.

Maps a Pac4J CommonProfile to our BasicProfile.

Handles null values from Java interop defensively. This is a pure function that can be tested independently of ZIO effects.

Value parameters

profile

Pac4J CommonProfile (Java object, may have null values)

Attributes

Returns

BasicProfile with optional fields for missing data

Throws
IllegalArgumentException

if profile ID is null or empty Example:

val pac4jProfile = new CommonProfile()
pac4jProfile.setId("user-123")
pac4jProfile.addAttribute("name", "John Doe")
pac4jProfile.addAttribute("email", "john@example.com")
pac4jProfile.addAttribute("roles", java.util.Arrays.asList("admin", "user"))
val basicProfile = adapter.mapProfile(pac4jProfile)
// BasicProfile(UserId("user-123"), Some(UserName("John Doe")), Some(Email("john@example.com")), None, Set(UserRole("admin"), UserRole("user")))

Inherited methods

def currentAccessToken: UIO[Option[AccessToken]]

Attributes

Inherited from:
AuthenticationService
def loggedIn(user: AuthedUserInfo): UIO[Unit]

Attributes

Inherited from:
AuthenticationService
def provideCurrentUser[R, E, A](effect: ZIO[R & CurrentUser, E, A]): ZIO[R, E | AuthenticationError, A]

Attributes

Inherited from:
AuthenticationService

Concrete fields

override val currentUserInfo: UIO[Option[AuthedUserInfo]]
val layer: ZLayer[Any, Nothing, AuthenticationService]