liveBook · Manning

RegisteredClientRepository

As explained in Spring in Action, Sixth Edition

RegisteredClientRepository is a Spring Security interface for storing and retrieving registered OAuth 2 client details.

An authorization server needs to know which applications may request authorization on a user’s behalf. RegisteredClientRepository holds those client details, much as a user repository holds user details. It can find a registered client by its internal ID or client ID. section 8.2

@Bean
public RegisteredClientRepository registeredClientRepository(
        PasswordEncoder passwordEncoder) {
  RegisteredClient registeredClient = 
    RegisteredClient.withId(UUID.randomUUID().toString())
      .clientId("taco-admin-client")
      .clientSecret(passwordEncoder.encode("secret"))
      .clientAuthenticationMethod(
              ClientAuthenticationMethod.CLIENT_SECRET_BASIC)
      .authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
      .authorizationGrantType(AuthorizationGrantType.REFRESH_TOKEN)
      .redirectUri(
          "http://127.0.0.1:9090/login/oauth2/code/taco-admin-client")
      .scope("writeIngredients")
      .scope("deleteIngredients")
      .scope(OidcScopes.OPENID)
      .clientSettings(
          clientSettings -> clientSettings.requireUserConsent(true))
      .build();
  return new InMemoryRegisteredClientRepository(registeredClient);
}

This bean registers one client in memory. Its details include an encoded secret, supported grant types, a redirect URI, scopes, and a requirement for user consent. section 8.2

The in-memory implementation suits demonstrations and tests. For production, a custom implementation could retrieve client details from a database or another source. section 8.2

How Spring in Action, Sixth Edition covers it

How deep it goes
Shows lookup methods and an in-memory bean configuration; defers a production-ready custom implementation.
Examples
Registers one client with authorization-code and refresh-token grants, an encoded secret, a redirect URI, and three scopes.
What it assumes
Introduces the repository through a user-repository analogy while assuming familiarity with Spring beans and a PasswordEncoder.
What you can do after
Operate/configure it by declaring an in-memory RegisteredClientRepository bean for a demonstration authorization server.
How it connects
Connects registered clients to authorization grants, redirect URIs, scopes, user consent, and password encoding.

Also explained in

Compare how 2 books explain RegisteredClientRepository →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.