Spring OpenID Client

Spring OpenID Connect Client

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

tech.rsqn
ArtifactId

ArtifactId

spring-openid-client
Last Version

Last Version

1.0.10
Release Date

Release Date

Type

Type

jar
Description

Description

Spring OpenID Client
Spring OpenID Connect Client
Project URL

Project URL

https://github.com/rsqn/spring-openid-client
Source Code Management

Source Code Management

https://github.com/rsqn/spring-openid-client

Download spring-openid-client

How to add to project

<!-- https://jarcasting.com/artifacts/tech.rsqn/spring-openid-client/ -->
<dependency>
    <groupId>tech.rsqn</groupId>
    <artifactId>spring-openid-client</artifactId>
    <version>1.0.10</version>
</dependency>
// https://jarcasting.com/artifacts/tech.rsqn/spring-openid-client/
implementation 'tech.rsqn:spring-openid-client:1.0.10'
// https://jarcasting.com/artifacts/tech.rsqn/spring-openid-client/
implementation ("tech.rsqn:spring-openid-client:1.0.10")
'tech.rsqn:spring-openid-client:jar:1.0.10'
<dependency org="tech.rsqn" name="spring-openid-client" rev="1.0.10">
  <artifact name="spring-openid-client" type="jar" />
</dependency>
@Grapes(
@Grab(group='tech.rsqn', module='spring-openid-client', version='1.0.10')
)
libraryDependencies += "tech.rsqn" % "spring-openid-client" % "1.0.10"
[tech.rsqn/spring-openid-client "1.0.10"]

Dependencies

compile (12)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.21
org.springframework : spring-core jar 4.3.2.RELEASE
org.springframework : spring-beans jar 4.3.2.RELEASE
org.springframework : spring-context jar 4.3.2.RELEASE
org.springframework : spring-web jar 4.3.2.RELEASE
org.springframework.security : spring-security-web jar 4.2.3.RELEASE
org.springframework.security : spring-security-config jar 4.2.3.RELEASE
org.springframework.security.oauth : spring-security-oauth2 jar 2.0.4.RELEASE
joda-time : joda-time jar 2.8.1
com.fasterxml.jackson.core : jackson-annotations jar 2.8.1
com.fasterxml.jackson.core : jackson-core jar 2.8.1
com.fasterxml.jackson.core : jackson-databind jar 2.8.1

provided (1)

Group / Artifact Type Version
javax.servlet : javax.servlet-api jar 4.0.0-b01

Project Modules

There are no modules declared in this project.

spring-openid-client

An "off the shelf" implementation of spring as an oauth2 or openid connect client.

There is nothing special in here and this does nothing that spring does not do out of the box.

However there are so many examples "on the internet" nowdays and many of them make assumptions on technical stacks or don't provide a full working solution that it can actually be difficult to get this going as a client only.

This module is simply to alleviate the need to learn something that really should be just a commodity

How do I use this?

Add this dependency

 <dependency>
    <groupId>tech.rsqn</groupId>
    <artifactId>spring-openid-client</artifactId>
    <version>1.0.3</version>
 </dependency>

Add spring dependencies to your project as the dependencies in this project are scoped as "provided"

todo - have a look at the POM file

Ensure these properties are available in your spring context

oauth2.authUri=XX
oauth2.accessTokenUri=XX
oauth2.userInfoUri=XX
oauth2.clientId=XX
oauth2.clientSecret=XX
oauth2.scope=trust,openid
oauth2.authenticationScheme=header

Create a web security configuration class like this in your project

    
@Configuration
@EnableWebSecurity
public class OAuth2WebSecurityConfigurer extends WebSecurityConfigurerAdapter {

    private final String AUTH_URI = "/app_auth";

    @Bean
    public AuthenticationEntryPoint authenticationEntryPoint() {
        return new LoginUrlAuthenticationEntryPoint(AUTH_URI);
    }

    @Bean
    public OpenIDConnectAuthenticationFilter openIdConnectAuthenticationFilter() {
        return new OpenIDConnectAuthenticationFilter(AUTH_URI);
    }

    @Bean
    public OAuth2ClientContextFilter oAuth2ClientContextFilter() {
        return new OAuth2ClientContextFilter();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.addFilterAfter(oAuth2ClientContextFilter(), AbstractPreAuthenticatedProcessingFilter.class)
                .addFilterAfter(openIdConnectAuthenticationFilter(), OAuth2ClientContextFilter.class)
                .exceptionHandling().authenticationEntryPoint(authenticationEntryPoint())
                .and().authorizeRequests()
                .antMatchers(HttpMethod.GET, "/unprotected").permitAll()
                .antMatchers(HttpMethod.GET, "/*").authenticated();
    }
}

Ensure this is in your spring config

    <context:annotation-config/>
    <context:component-scan base-package="tech.rsqn.springopenidclient" />
    <context:component-scan base-package="THE_PACKAGE_YOU_HAVE_THE_ABOVE_CONFIGURATION_CLASS_IN" />

... aaaand it should work

tech.rsqn

Rogue Squadron

Versions

Version
1.0.10
1.0.9
1.0.8
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0