Protected
authExecuted when encountering an authentication error.
req
res
error
void
Readonly
clientunologin instance
Readonly
loginProtected
loginReadonly
requireOnly executes the next handler if the user is logged in.
Will trigger the AuthErrorHandler otherwise.
Must be preceded by the parseLogin middleware.
req
res
next
Promise
Protected
getInternal
Result of getUserTokenOptional may be stored in with the response object.
This function acts as a helper to retrieve the cached value.
This function is meant to be used in conjunction with Express-like frameworks
where one middleware function is called after another,
passing values using res.locals
.
parsed user token cached in res.locals
res
URL
req
res (not used)
Returns a UserHandle from the current request.
Returns null
if the request contains no login information.
IMPORTANT:
This function is synchronous and the UserHandle can therefore not be trusted to be authenticated.
The returned UserHandle can however be used in any API call that accepts a UserHandle as a parameter.
In this case, the authentication happens on the unologin API.
Use getUserTokenOptional for optional authentication. Use getUserToken for required authentication.
UserHandle | null
req
res
Authenticates the user and returns a Promise to the UserToken.
Requires the user to be logged in.
The resolved UserToken is authenticated and can be trusted.
getUserTokenOptional for optional authentication.
APIError 403 unauthorized if not logged in.
APIError 403 unauthorized if login token invalid.
Promise
req
res
Authenticates the user and returns a Promise to the UserToken.
Does not require the user to be logged in. Does nothing if no login cookie is present and returns null.
The resolved UserToken is authenticated and can be trusted if not null.
Requires a cookie parser.
getUserToken for required authentication.
Promise
req
res
Extracts the cached UserToken from previous call to getUserTokenOptional or getUserToken
Returns null if not logged in.
Will only return the token if preceded by parseLogin or in onLoginSuccess.
Will return null
otherwise.
Use getUserToken for an authenticated async version.
token
Express Response object
Internal
Handles the unologin login event. Returns a URL to redirect the user to.
Promise
req
res
Logs out a user and calls next()
Promise
req
res
Optional
next: NextFunctionnext
Decide what to do on auth error.
void
Express handler
Add a callback that is called after the login event has finished but before the response is sent to the client.
The UserToken passed to handler
is authenticated an can be trusted.
void
(req, res, userToken) => unknown
Middleware to parse login information.
Will let any request pass where the user is not logged in.
for making sure only authenticated requests get past.
Promise<UserToken | null>
request
response
optional next function
Protected
resetResets/deletes login cookies.
void
req
res
Protected
setImplements cookie setting for Express.
void
req (not used)
res
name
value
options
Protected
setInternal
Set the login cookies for a response.
void
req
rest
cookie to set
cookie options
Generated using TypeDoc
Implements HttpHandlers for Express.