authorizationGrantType cannot be null in Spring Security 5 OAuth Client and Spring Boot 2.0

Hantsy picture Hantsy · Mar 16, 2018 · Viewed 8.5k times · Source

I followed the Spring Security 5.0 official reference documentation and sample codes oauth2login to setup OAuth2/OIDC authentication in my project, but it failed and I got the following exception when I booted up my application by mvn spring-boot:run.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientRegistrationRepository' 
defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientRegistrationRepositoryConfiguration.class]: 
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: 
Failed to instantiate [org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository]: 
Factory method 'clientRegistrationRepository' threw exception; 
nested exception is java.lang.IllegalArgumentException: authorizationGrantType cannot be null

I was using the default configuration provided by Spring Boot, and just added some basic dependencies into projects, such as spring-security-config, spring-security-oauth2-client, spring-security-oauth2-jsoe etc.

Updated:

I'v found the reason, for custom OAuth2 providers, such as Gitlab, I have to add grant type, redirectUritemplate, scope, clientName etc, but OpenID Connect specification has a configuration endpoint protocol, eg: https://gitlab.com/.well-known/openid-configuration , is there possible to make Spring Security to read these info automatically?

Answer

Arpeet picture Arpeet · Dec 4, 2019

use redirect-uri instead of redirect-uri-template if use SpringBoot v2.2.1 RELEASE