AuthService

Shared service for authentication logic, including JWT handling and token issuing.

Types

Link copied to clipboard

HttpOnly cookie for the refresh token.

Properties

Link copied to clipboard
val jwtVerifier: JWTVerifier

The JWT verifier used to validate access tokens.

Functions

Link copied to clipboard
context(_: Raise<Issue>)
fun authenticate(request: Request): Principal

Shared authentication logic for both OAuth and Password handlers.

Link copied to clipboard

Creates an access token for the given user.

Link copied to clipboard
context(_: JdbcTransaction)
fun findOAuthUser(provider: String, providerUserId: String): UserEntity?

Finds a user associated with an OAuth provider and user ID.

Link copied to clipboard
fun generateSecret(bytes: Int = 32): String

Generates a secure random secret of the given bytes length, encoded as Base64.

Link copied to clipboard
fun hash(text: String): ByteArray

Hashes the given text using SHA-256.

Link copied to clipboard
context(_: JdbcTransaction, auth: AuthType)
fun UserEntity.issueTokenPair(): TokenModel

Issues a pair of access and refresh tokens for the given user.

Link copied to clipboard
context(_: JdbcTransaction, _: Raise<Issue>)
fun linkOrCreateUser(provider: String, providerUserId: String, preferredUsername: String, email: String, currentPrincipal: Principal? = null): UserEntity

Links a new OAuth account to an existing user or creates a new user.

Link copied to clipboard
context(_: Raise<Issue>, req: Request)
fun logout(): Cookie

Shared logic to logout by revoking the refresh token and clearing the cookie.

context(_: Raise<Issue>)
fun logout(refreshToken: String)

Revokes the given refresh token.

Link copied to clipboard
context(_: Raise<Issue>, _: AuthType, req: Request)
fun refresh(): ApiResponse<TokenResponseModel, Empty>
Link copied to clipboard
context(_: Raise<Issue>, auth: AuthType)
fun refreshTokens(refreshToken: String): TokenModel

Shared logic to refresh a token pair using a refresh token.

Link copied to clipboard
context(_: Raise<Issue>)
fun verifyRefreshToken(refreshToken: String): UserEntity

Verifies the given refreshToken and returns the associated UserEntity if successful.

Link copied to clipboard
context(_: Raise<Issue>)
fun verifyToken(token: String): Uuid

Verifies the given token and returns the subject (user ID) if successful.