Fork me on GitHub

REST API (v5.1)

pac4j allows you to validate users via a REST API.

1) Dependency

You need to use the following module: pac4j-http.

Example (Maven dependency):

<dependency>
    <groupId>org.pac4j</groupId>
    <artifactId>pac4j-http</artifactId>
    <version>${pac4j.version}</version>
</dependency>

2) RestAuthenticator

The RestAuthenticator validates the provided username/password by POSTing them as a basic authentication to an URL which must return:

In case of a successful authentication, a RestProfile is returned.

Example of a correct server response:

{
  "id": "1234",
  "attributes": {
    "firstName": "Jerome"
  }
}

Example of a client:

RestAuthenticator authenticator = new RestAuthenticator("http://rest-api-url");
DirectBasicAuthClient directBasicAuthClient = new DirectBasicAuthClient(authenticator);