Last active
March 1, 2021 10:40
-
-
Save Enigo/bf133a34fba854d8660b8708edab4c78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@EnableConfigurationProperties(OneLoginConfigs.class) | |
@RequiredArgsConstructor(onConstructor_ = @Autowired) | |
@Configuration | |
public class SecurityConfiguration extends WebSecurityConfigurerAdapter { | |
private final OneLoginConfigs oneLoginConfigs; | |
@Override | |
public void configure(final HttpSecurity http) throws Exception { | |
http.authorizeRequests() | |
.antMatchers("/", "/login**", "/oauth2/authorization/**").permitAll() | |
.anyRequest().authenticated() | |
.and() | |
.oauth2Login(); | |
} | |
@Bean | |
public ClientRegistrationRepository clientRegistrationRepository() { | |
return new InMemoryClientRegistrationRepository(createClientRegistration()); | |
} | |
private ClientRegistration createClientRegistration() { | |
return ClientRegistration.withRegistrationId("onelogin") | |
.clientId(oneLoginConfigs.getClientId()) | |
.clientSecret(oneLoginConfigs.getClientSecret()) | |
.clientAuthenticationMethod(ClientAuthenticationMethod.BASIC) | |
.authorizationUri("https://company.onelogin.com/oidc/2/auth") | |
.tokenUri("https://company.onelogin.com/oidc/2/token") | |
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE) | |
.redirectUri("{baseUrl}/login/oauth2/code/{registrationId}") | |
.scope("openid", "profile", "email”) | |
.userInfoUri("https://company.onelogin.com/oidc/2/me") | |
.userNameAttributeName(IdTokenClaimNames.SUB) | |
.jwkSetUri("https://company.onelogin.com/oidc/2/certs") | |
.clientName("Zoo") | |
.build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment