Authenticators

CookieAuthenticator

To configure the CookieAuthenticator service you must use the CookieAuthenticatorSettings class. This class has the following form:

case class CookieAuthenticatorSettings(
  cookieName: String = "id",
  cookiePath: String = "/",
  cookieDomain: Option[String] = None,
  secureCookie: Boolean = true,
  httpOnlyCookie: Boolean = true,
  useFingerprinting: Boolean = true,
  cookieMaxAge: Option[FiniteDuration] = None,
  authenticatorIdleTimeout: Option[FiniteDuration] = None,
  authenticatorExpiry: FiniteDuration = 12 hours)
PropertyDescription
cookieNameThe cookie name
cookiePathThe cookie path
cookieDomainThe cookie domain
secureCookieWhether this cookie is secured, sent only for HTTPS requests.

Note:
This should be disabled for testing on localhost without SSL, otherwise cookie couldn't be set
httpOnlyCookieWhether this cookie is HTTP only, i.e. not accessible from client-side JavaScript code
useFingerprintingIndicates if a fingerprint of the user should be stored in the authenticator
cookieMaxAgeThe duration a cookie expires. None for a transient cookie
authenticatorIdleTimeoutThe duration an authenticator can be idle before it timed out. This means, if you set the time to 5 minutes then a user will be logged out if he visits the site again after 5 minutes and 1 second. If he visits the site before the authenticator times out then he has again 5 minutes until the authenticator times out.
authenticatorExpiryThe duration an authenticator expires after it was created. This means, if the timeout is set to 1 day, then the authenticator expires definitely after one day.

Example

authenticator.cookieName = "authenticator"
authenticator.cookiePath = "/"
authenticator.secureCookie = false
authenticator.httpOnlyCookie = true
authenticator.useFingerprinting = true
authenticator.authenticatorIdleTimeout = 30 minutes
authenticator.authenticatorExpiry = 12 hours

SessionAuthenticator

To configure the SessionAuthenticator service you must use the SessionAuthenticatorSettings class. This class has the following form:

case class SessionAuthenticatorSettings(
  sessionKey: String = "authenticator",
  useFingerprinting: Boolean = true,
  authenticatorIdleTimeout: Option[FiniteDuration] = None,
  authenticatorExpiry: FiniteDuration = 12 hours)
PropertyDescription
sessionKeyThe key of the authenticator in the session
useFingerprintingIndicates if a fingerprint of the user should be stored in the
authenticatorIdleTimeoutThe duration an authenticator can be idle before it timed out. This means, if you set the time to 5 minutes then a user will be logged out if he visits the site again after 5 minutes and 1 second. If he visits the site before the authenticator times out then he has again 5 minutes until the authenticator times out.
authenticatorExpiryThe duration an authenticator expires after it was created. This means, if the timeout is set to 1 day, then the authenticator expires definitely after one day.

Example

authenticator.sessionKey = "authenticator"
authenticator.useFingerprinting = true
authenticator.authenticatorIdleTimeout = 30 minutes
authenticator.authenticatorExpiry = 12 hours

BearerTokenAuthenticator

To configure the BearerTokenAuthenticator service you must use the BearerTokenAuthenticatorSettings class. This class has the following form:

case class BearerTokenAuthenticatorSettings(
  fieldName: String = "X-Auth-Token",
  requestParts: Option[Seq[RequestPart.Value]] = Some(Seq(RequestPart.Headers)),
  authenticatorIdleTimeout: Option[FiniteDuration] = None,
  authenticatorExpiry: FiniteDuration = 12 hours)
PropertyDescription
fieldNameThe name of the field in which the token will be transferred in any part of the request
requestPartsSome request parts from which a value can be extracted or None to extract values from any part of the request. Default is set to Headers only. This functionality is useful if the token should be transported into another part of the request. For a WebSocket, opened from JavaScript, the token must be transported in the query string, because the JavaScript WebSockets API doesn't allow additional headers.
authenticatorIdleTimeoutThe duration an authenticator can be idle before it timed out. This means, if you set the time to 5 minutes then a user will be logged out if he visits the site again after 5 minutes and 1 second. If he visits the site before the authenticator times out then he has again 5 minutes until the authenticator times out.
authenticatorExpiryThe duration an authenticator expires after it was created. This means, if the timeout is set to 1 day, then the authenticator expires definitely after one day.

Example

📘

Enumeration based values in the configuration

The authenticator.requestParts configuration property uses Enumeration based values. This values can be parsed with Ficus if you import the additional EnumerationReader.

authenticator.fieldName = "X-Auth-Token"
authenticator.authenticatorIdleTimeout = 30 minutes
authenticator.authenticatorExpiry = 12 hours

JWTAuthenticator

To configure the JWTAuthenticator service you must use the JWTAuthenticatorSettings
class. This class has the following form:

case class JWTAuthenticatorSettings(
  fieldName: String = "X-Auth-Token",
  requestParts: Option[Seq[RequestPart.Value]] = Some(Seq(RequestPart.Headers)),
  issuerClaim: String = "play-silhouette",
  authenticatorIdleTimeout: Option[FiniteDuration] = None,
  authenticatorExpiry: FiniteDuration = 12 hours,
  sharedSecret: String)
PropertyDescription
fieldNameThe name of the field in which the token will be transferred in any part of the request
requestPartsSome request parts from which a value can be extracted or None to extract values from any part of the request. Default is set to Headers only. This functionality is useful if the token should be transported into another part of the request. For a WebSocket, opened from JavaScript, the token must be transported in the query string, because the JavaScript WebSockets API doesn't allow additional headers.
issuerClaimThe issuer claim identifies the principal that issued the JWT
authenticatorIdleTimeoutThe duration an authenticator can be idle before it times out. This means, if you set the time to 5 minutes then a user will be logged out if he visits the site again after 5 minutes and 1 second. If he visits the site before the authenticator times out then he has again 5 minutes until the authenticator times out.
authenticatorExpiryThe duration an authenticator expires after it was created. This means, if the timeout is set to 1 day, then the authenticator expires definitely after one day.
sharedSecretThe shared secret to sign the JWT

Example

📘

Enumeration based values in the configuration

The authenticator.requestParts configuration property uses Enumeration based values. This values can be parsed with Ficus if you import the additional EnumerationReader.

authenticator.fieldName = "X-Auth-Token"
authenticator.requestParts = ["headers"]
authenticator.issuerClaim = "play-angular-silhouette"
authenticator.authenticatorExpiry = 12 hours
authenticator.sharedSecret = "changeme"

What’s Next