Authentication

abstract class Authentication<P> : Middleware

Special Middleware to use in at http API to provide an authentication for every request. The type-parameter P represents the principal information, which contains all login-information needed to authenticate against the external HTTP API. The principal information is held inside and available as flow by calling data. To use this Middleware you need to implement the addAuthentication method, where you get the principal information, when available, to add it to your requests. To implement the client side of authentication process you also need to implement the authenticate method in which you specify what is needed to authenticate the user (e.g. open up a login modal). When your authentication process is done you have to call the complete function and set your principal. Then all requests, that have been initialized while the authentication was running, will be re-executed with the additional authentication information provided by the addAuthentication method. When the user logs out you have to call the clear function to clear all authentication information.

Constructors

Authentication
Link copied to clipboard
js
fun Authentication()

Functions

addAuthentication
Link copied to clipboard
js
abstract fun addAuthentication(request: Request, principal: P?): Request
Adds the authentication information to all requests by using the given principal.
authenticate
Link copied to clipboard
js
abstract fun authenticate()
implements the authentication process.
clear
Link copied to clipboard
js
fun clear()
clears the current principal information.
complete
Link copied to clipboard
js
fun complete(principal: P)
completes the authentication process by setting the principal.
enrichRequest
Link copied to clipboard
js
suspend override fun enrichRequest(request: Request): Request
enriches requests with additional information.
handleResponse
Link copied to clipboard
js
suspend override fun handleResponse(response: Response): Response
handles responses.
start
Link copied to clipboard
js
fun start()
starts the authentication process.
stopPropagation
Link copied to clipboard
js
open fun Response.stopPropagation(): Response
stops propagation of a response to the following Middlewares in the chain

Properties

authenticated
Link copied to clipboard
js
val authenticated: Flow<Boolean>
flow of the information whether the user is authenticated or not
current
Link copied to clipboard
js
val current: P?
Returns the current principal information.
data
Link copied to clipboard
js
val data: Flow<P?>
flow of the current principal P
statusCodesEnforcingAuthentication
Link copied to clipboard
js
open val statusCodesEnforcingAuthentication: Set<Int>
List of HTTP-Status-Codes forcing an authentication.