Skip to content

Examples

All examples follow the same procedure: they send the user to sign in with Certilia with PKCE (S256), state and nonce, on the way back exchange the code for tokens, check the ID token (signature, issuer, audience, expiry and nonce) and show the data about the user from it. A standard OpenID Connect library does all of this and needs only the values from the Integration tab on the application’s page; the examples read them from environment variables:

Variable Value
CERTILIA_ISSUER Issuer, on the test system https://idp.test.certilia.com/oauth2/token. The library adds /.well-known/openid-configuration to it (OpenID Discovery).
CERTILIA_CLIENT_ID Client ID.
CERTILIA_CLIENT_SECRET Client Secret. Read it from your environment’s secrets, never from code.
SESSION_SECRET Only for Node.js and Python: a long random value the example signs its session cookie with.

Each example runs on a separate port on your computer. In the application’s settings, under Redirect URIs, enter the address of the example you are trying (HTTP is allowed only for localhost) and then open its sign-in address in the browser:

Example Redirect URI Sign-in
Java http://localhost:3104/login/oauth2/code/certilia http://localhost:3104/
.NET http://localhost:3103/callback http://localhost:3103/login
Python http://localhost:3105/callback http://localhost:3105/login
Node.js http://localhost:3101/callback http://localhost:3101/login
PHP http://localhost:3102/callback http://localhost:3102/login
Go http://localhost:3106/callback http://localhost:3106/login

After the sign-in the example shows the data from the ID token as JSON. Identify the user by sub (the OIB). The first name, last name and e-mail address come as given_name, family_name and email when the application asks for them and the user approved them.

Java 25, Spring Boot 4.1.2 with Spring Security (OAuth2 Client) and Maven. Spring adds state and nonce automatically, and OAuth2AuthorizationRequestCustomizers.withPkce() turns on PKCE for a server application.

pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>4.1.2</version>
</parent>
<groupId>com.example</groupId>
<artifactId>certilia-sign-in</artifactId>
<version>1.0.0</version>
<properties>
<java.version>25</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security-oauth2-client</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
src/main/resources/application.yml
server:
port: 3104
spring:
security:
oauth2:
client:
registration:
certilia:
client-id: ${CERTILIA_CLIENT_ID}
client-secret: ${CERTILIA_CLIENT_SECRET}
scope: openid
provider:
certilia:
issuer-uri: ${CERTILIA_ISSUER}
src/main/java/com/example/CertiliaSignIn.java
package com.example;
import java.util.Map;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
import org.springframework.security.oauth2.client.web.DefaultOAuth2AuthorizationRequestResolver;
import org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestCustomizers;
import org.springframework.security.oauth2.core.oidc.user.OidcUser;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class CertiliaSignIn {
public static void main(String[] args) {
SpringApplication.run(CertiliaSignIn.class, args);
}
// Every page needs a sign-in; Spring sends the user to Certilia with PKCE (S256), state and nonce,
// and on /login/oauth2/code/certilia exchanges the code for tokens and checks the ID token.
@Bean
SecurityFilterChain security(HttpSecurity http, ClientRegistrationRepository registrations) throws Exception {
var resolver = new DefaultOAuth2AuthorizationRequestResolver(registrations, "/oauth2/authorization");
resolver.setAuthorizationRequestCustomizer(OAuth2AuthorizationRequestCustomizers.withPkce());
http.authorizeHttpRequests(requests -> requests.anyRequest().authenticated())
.oauth2Login(login -> login.authorizationEndpoint(endpoint -> endpoint.authorizationRequestResolver(resolver)));
return http.build();
}
@GetMapping("/")
Map<String, Object> user(@AuthenticationPrincipal OidcUser user) {
return user.getIdToken().getClaims();
}
}
Prozor terminala
mvn package
java -jar target/certilia-sign-in-1.0.0.jar