问题描述:

I have some questions to client-side OAuth2:

  • How can i initialize OAuth2RestTemplate bean on app startup when i dont know credentials for OAuth2ProtectedResourceDetails? I need to modify those details in runtime.

  • Is there any kind of Null/Empty implementation of OAuth2ProtectedResourceDetails? If i pass not initialized details, Spring will throw exception - how to handle that, and not print into console on app startup?

  • Spring bean OAuth2RestTemplate is creating on application startup (context is created). And in that time oauth template needs some OAuth2ProtectedResourceDetails in constructor. But i want populate client credentials later, for example from database, when user will add clientId and secret from Gui. User will also be able to edit those credentials, delete or add new. How to handle that situation? How to update details in runtime?

Example AppConfig.class:

@Bean

public DefaultAccessTokenRequest accessTokenRequest(){

return new DefaultAccessTokenRequest();

}

@Bean

public OAuth2ClientContext oAuth2ClientContext(){

return new DefaultOAuth2ClientContext(accessTokenRequest());

}

@Bean

public OAuth2RestTemplate oAuth2RestTemplate(){

OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(oAuth2ProtectedResourceDetails(), oAuth2ClientContext());

return restTemplate;

}

@Bean

public OAuth2ProtectedResourceDetails oAuth2ProtectedResourceDetails () {

ClientCredentialsResourceDetails resource = new ClientCredentialsResourceDetails();

// i dont know this property values - user will provide it later through Gui, and i want read it then from Db and update those resource details

resource.setAccessTokenUri("");

resource.setClientId("");

resource.setClientSecret("");

// additional properties...

return resource;

}

Thanks.

相关阅读:
Top