Skip to content

Add SupplierClientRegistrationRepository #12967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jzheaux opened this issue Apr 4, 2023 · 2 comments · Fixed by #12972
Closed

Add SupplierClientRegistrationRepository #12967

jzheaux opened this issue Apr 4, 2023 · 2 comments · Fixed by #12972
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) status: ideal-for-contribution An issue that we actively are looking for someone to help us with type: enhancement A general enhancement

Comments

@jzheaux
Copy link
Contributor

jzheaux commented Apr 4, 2023

SupplierJwtDecoder allows for deferring the query to the authorization server for JWKS, allowing resource servers to restart more resiliently (since they don't require the authorization server to be up at that time).

It would be nice for OAuth 2.0 Cilent applications to have the same startup resiliency. With SupplierClientRegistrationRepository, then applications could defer the construction like so:

@Bean 
ClientRegistrationRepository clientRegistrations() {
    return new SupplierClientRegistrationRepository(() -> {
        ClientRegistration registration = ClientRegistrations.fromIssuerLocation("http://localhost:8080").build();
        return new InMemoryClientRegistrationRepository(registration);
    });
}
@jzheaux jzheaux added status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement status: ideal-for-contribution An issue that we actively are looking for someone to help us with in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 4, 2023
@yangao-cn
Copy link

@jzheaux Imagine a scenario where there are many ClientRegistrations, such as 500, and each ClientRegistration's initialization need send a request to obtain issuer's metadata, which may take a lot of time to initialize ClientRegistrationRepository . Can we do lazy initialization for each ClientRegistration?

@yangao-cn
Copy link

@jzheaux
The SupplierClientRegistration, similar to SuppliedJwtDecoder, can help us solve this problem, what do you think? I can provide a PR if you think this is a good suggestion.

public class SupplierClientRegistration {
	private final String registrationId;
	private final Supplier<ClientRegistration> registrationSupplier;

	public SupplierClientRegistration(String registrationId, Supplier<ClientRegistration> registrationSupplier) {
		Assert.hasText(registrationId, "registrationId cannot be empty");
		Assert.notNull(registrationSupplier, "registrationSupplier cannot be null");
		this.registrationId = registrationId;
		this.registrationSupplier = SingletonSupplier.of(() -> {
			try {
				return registrationSupplier.get();
			}
			catch (Exception ex) {
				throw wrapException(ex);
			}
		});
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) status: ideal-for-contribution An issue that we actively are looking for someone to help us with type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants