---
updatedAt: 2025-04-23T20:29:44.000Z
agentTools:
  projectIndex: https://silhouette.readme.io/llms.txt
---

# Authenticators

## CookieAuthenticator

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

```scala
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)
```

<Table align={["left","left"]}>
  <thead>
    <tr>
      <th>
        Property
      </th>

      <th>
        Description
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        `cookieName`
      </td>

      <td>
        The cookie name
      </td>
    </tr>

    <tr>
      <td>
        `cookiePath`
      </td>

      <td>
        The cookie path
      </td>
    </tr>

    <tr>
      <td>
        `cookieDomain`
      </td>

      <td>
        The cookie domain
      </td>
    </tr>

    <tr>
      <td>
        `secureCookie`
      </td>

      <td>
        Whether 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
      </td>
    </tr>

    <tr>
      <td>
        `httpOnlyCookie`
      </td>

      <td>
        Whether this cookie is HTTP only, i.e. not accessible from client-side JavaScript code
      </td>
    </tr>

    <tr>
      <td>
        `useFingerprinting`
      </td>

      <td>
        Indicates if a fingerprint of the user should be stored in the authenticator
      </td>
    </tr>

    <tr>
      <td>
        `cookieMaxAge`
      </td>

      <td>
        The duration a cookie expires. `None` for a transient cookie
      </td>
    </tr>

    <tr>
      <td>
        `authenticatorIdleTimeout`
      </td>

      <td>
        The 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.
      </td>
    </tr>

    <tr>
      <td>
        `authenticatorExpiry`
      </td>

      <td>
        The 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.
      </td>
    </tr>
  </tbody>
</Table>

### Example

```scala
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:

```scala
case class SessionAuthenticatorSettings(
  sessionKey: String = "authenticator",
  useFingerprinting: Boolean = true,
  authenticatorIdleTimeout: Option[FiniteDuration] = None,
  authenticatorExpiry: FiniteDuration = 12 hours)
```

<Table align={["left","left"]}>
  <thead>
    <tr>
      <th>
        Property
      </th>

      <th>
        Description
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        `sessionKey`
      </td>

      <td>
        The key of the authenticator in the session
      </td>
    </tr>

    <tr>
      <td>
        `useFingerprinting`
      </td>

      <td>
        Indicates if a fingerprint of the user should be stored in the
      </td>
    </tr>

    <tr>
      <td>
        `authenticatorIdleTimeout`
      </td>

      <td>
        The 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.
      </td>
    </tr>

    <tr>
      <td>
        `authenticatorExpiry`
      </td>

      <td>
        The 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.
      </td>
    </tr>
  </tbody>
</Table>

### Example

```scala
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:

```scala
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)
```

<Table align={["left","left"]}>
  <thead>
    <tr>
      <th>
        Property
      </th>

      <th>
        Description
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        `fieldName`
      </td>

      <td>
        The name of the field in which the token will be transferred in any part of the request
      </td>
    </tr>

    <tr>
      <td>
        `requestParts`
      </td>

      <td>
        Some 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.
      </td>
    </tr>

    <tr>
      <td>
        `authenticatorIdleTimeout`
      </td>

      <td>
        The 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.
      </td>
    </tr>

    <tr>
      <td>
        `authenticatorExpiry`
      </td>

      <td>
        The 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.
      </td>
    </tr>
  </tbody>
</Table>

### 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].
>
> [Ficus]: https://github.com/iheartradio/ficus
>
> [EnumerationReader]: https://github.com/iheartradio/ficus#enumeration-support

```scala
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:

```scala
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)
```

<Table align={["left","left"]}>
  <thead>
    <tr>
      <th>
        Property
      </th>

      <th>
        Description
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        `fieldName`
      </td>

      <td>
        The name of the field in which the token will be transferred in any part of the request
      </td>
    </tr>

    <tr>
      <td>
        `requestParts`
      </td>

      <td>
        Some 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.
      </td>
    </tr>

    <tr>
      <td>
        `issuerClaim`
      </td>

      <td>
        The issuer claim identifies the principal that issued the JWT
      </td>
    </tr>

    <tr>
      <td>
        `authenticatorIdleTimeout`
      </td>

      <td>
        The 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.
      </td>
    </tr>

    <tr>
      <td>
        `authenticatorExpiry`
      </td>

      <td>
        The 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.
      </td>
    </tr>

    <tr>
      <td>
        `sharedSecret`
      </td>

      <td>
        The shared secret to sign the JWT
      </td>
    </tr>
  </tbody>
</Table>

### 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].
>
> [Ficus]: https://github.com/iheartradio/ficus
>
> [EnumerationReader]: https://github.com/iheartradio/ficus#enumeration-support

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