This sample showcases the how to integrate a spring-boot application with WSO2 Identity Server for secure authentication using OpenID Connect standard.
-
Access WSO2 Identity Server Developer Portal .
-
Go to Applications and click New Application.
-
Click Show More
-
Open the OIDC Web Application template.
-
Enter Name and Description and click Next.
-
Enter Callback URL.
The Callback URL is the exact location in the service provider's application where an authorization code would be sent. This should always be
{baseUrl}/login/oauth2/code/wso2
.If you want configure oidc logout also, then you need to add post-logout-url. You can add multiple callback urls. In WSO2 Identity Server, post-logout-url can be configured via callback URL.
Add the two callBack URLs: - http://localhost:8080/spring-boot-sample/login/oauth2/code/wso2 - http://localhost:8080/spring-boot-sample/login
-
Click Next
-
View the application details and Click Finish
-
Click on Access tab and Note the the Client ID and Client Secret that appears.
Field | Value |
---|---|
Service Provider Name | your-application-name |
Description | This is a spring-boot app |
CallBack Url | {baseUrl}/login/oauth2/code/wso2, {baseUrl}/spring-boot-app/login |
Eg:
Field | Value |
---|---|
Service Provider Name | sample-app |
Description | This is a spring-boot application |
CallBack Url | http://localhost:8080/spring-boot-app/login/oauth2/code/wso2,http://localhost:8080/spring-boot-app/login |
-
Download the certificate from the management console (for example, as IsCertificate.cer)
-
Locate $JAVA_HOME/jre/lib/security/cacerts
-
Import the certificate into the cacerts file using the following: keytool -import -alias isCertificate -keystore cacerts -file <IS_CERTIFICATE_FILE_LOCATION>
- You can clone this project and build it.
- Run
mvn clean install
. - Get the
spring-boot-sample.war
file fromtarget
folder. - Deploy the sample into the tomcat and start the tomcat.
- Access
http://localhost:8080/spring-boot-sample/login
if your tomcat is running in port 8080. If not, change the port and host accordingly.
-
Open the
application.yml
file located inspring-boot-sample/WEB-INF/classes
from the exploded war file. -
Update the following configuration. Please note that you should not change any other configurations
provider:
host: <server-host-name> #Change the host
client:
client-id: <application-client-id> #Change client-id
client-secret: <application-client-secret> # Change client-secret
post-logout-uri: <base-url>/spring-boot-sample/login
scope: openid
authorization-grant-type: authorization_code
Example:
provider:
host: https://localhost:9443 #Change the host
client:
client-id: LQTLEgDFil5Tyf0wS5KWUShkMDEa #Change client-id
client-secret: ZuFwLrbBKhp74NWT1zBIjXuXuYUa # Change client-secret
post-logout-uri: http://localhost:8080/spring-boot-sample/login
scope: openid
authorization-grant-type: authorization_code