Repositories

The role of repositories

The OIDC4J provider library has a number of domain objects living within it, from Oauth2 clients, to tokens, to users. These are all tracked by classes known as repositories. The suite of repository interfaces available are:

  • AuthorizationRepository
  • ClientRepository
  • GrantRepository
  • ScopeRepository
  • TokenRepository
  • UserRepository

An in-memory implementation of these repositories is provided by the library, but it is expected that developers will implement their own, using database technologies of their choosing.

We saw in the configuration section and in our example, that the OIDCPProvider class gives us a method called inMemoryDefaults, which gives us these in-memory implementations by default. These are all held in an instance of ServiceRegistry, which we can provide ourselves during construction of the OIDCProvider object:

var serviceRegistry =ServiceRegistry.builder()
                .withUserRepository(ourImplementationOfUserRepository())
                .withClientRepository(ourImplementationOfClientRepository())
                .withScopeRepository(ourImplementationOfScopeRepository())
                .withGrantRepository(ourImplementationOfGrantRepository())
                .withAuthorizationRepository(ourImplementationOfAuthorizationRepository())
                .withUserRepository(ourImplementationOfUserRepository())
                .withTokenRepository(ourImplementationOfTokenRepository())
                .build();

var provider = OIDCProvider.builder()
    .config(config)
    .serviceRegistry(serviceRegistry)
.build();