scribejava for spring boot autoconfigure.
- OAuth2ServiceDelegate. You can customize your own delegate. For example: SinaWeiboOAuth2ServiceDelegate
- Support for basic oauth2 authorization operations. For more information, please see BasicOAuth2LoginController
- Support for Authentication Success Handler and Failure Handler.
- Support for ApplicationEventPublisher.
For Maven
<dependency>
<groupId>com.youkol.support.scribejava</groupId>
<artifactId>scribejava-spring-boot-starter</artifactId>
<version>${scribejava.spring.version}</version>
</dependency>
Spring-boot application.yml
youkol:
oauth2:
web:
enabled: true # default true
authorize:
path: "/oauth2/authorize/{registrationId}" # default
callback:
path: "/oauth2/callback/{registrationId}" # default
client:
enabled: true
registration:
wechat_offical: # => OAuth2ServiceDelegate.getName()
client-id: [your apikey]
client-secret: [your apiSecret]
scope: [default scope]
redirect-uri: "{baseUrl}/oauth2/callback/{registrationId}?redirect_uri={redirect_uri}" # for example
For your project
@Configuration
public class ScribejavaConfig {
@Bean
public SinaWeiboOAuth2ServiceDelegate sinaWeiboOAuth2ServiceDelegate(
ClientRegistrationRepository clientRegistrationRepository,
Optional<ObjectMapper> objectMapper) {
SinaWeiboOAuth2ServiceDelegate delegate = new SinaWeiboOAuth2ServiceDelegate(clientRegistrationRepository);
delegate.setObjectMapper(objectMapper);
return delegate;
}
@Bean
public WeChatMpOAuth2ServiceDelegate weChatMpOAuth2ServiceDelegate(
ClientRegistrationRepository clientRegistrationRepository,
Optional<ObjectMapper> objectMapper) {
WeChatMpOAuth2ServiceDelegate delegate = new WeChatMpOAuth2ServiceDelegate(clientRegistrationRepository);
delegate.setObjectMapper(objectMapper);
return delegate;
}
@Bean
public AuthenticationSuccessHandler customAuthenticationSuccessHandler() {
return new CunstomAuthenticationSuccessHandler();
}
@Bean
public AuthenticationFailureHandler customAuthenticationFailureHandler() {
return new CunstomAuthenticationFailureHandler();
}
}
Thanks to spring and spring-security project. When the project allows, recommend spring-security.