This example shows how to register a new Openshift OAuthClient and authenticate your Springboot 3 application over Openshift.
Openshift brings it's own ability to register new OAuthClients. This is very useful if you want to authenticate your application over Openshift without using some OIDC provider like Keycloak.
You can read more about registering OAuthClients in Openshift here.
We built a simple Springboot 3 application to test the Authentication process and want to share this with you. Of course the same you can do with Quarkus or any other framework.
Sadly the Openshift OAuthClient doesn't bring a userinfo endpoint so we have to use the Openshift user endpoint to get the user information and patch it into the authentication process.
- Clone this repository
- Create a new Openshift project on which you want to give access rights to the user who will login
- Adapt the openshift/OAuthClient.yaml and set the password and redirect Url to your needs
- Login to your Openshift cluster in your terminal
- Apply the OAuthClient.yaml to your Openshift project by running
oc apply -f openshift/OAuthClient.yaml
- Adapt the application.yaml with your OAuthClient information or set the Environment Variables in your Run Config (use EnvFile plugin in IntelliJ to load the local.env file)
- The OPENSHIFT_OAUTH_URL you can get by running
oc get route oauth-openshift -n openshift-authentication -o json | jq .spec.host
- Run the application, open localhost:8080 in your browser and sign in to Openshift
- Your username will be displayed and your are authenticated
Your .env File should look like this:
OPENSHIFT_API_URL=https://api.someopenshift-host.net:6443
OPENSHIFT_OAUTH_URL=https://oauth-openshift.apps.someopenshift-host.net
OPENSHIFT_OAUTH_CLIENT_SECRET=yourGeneratedPasswordFrom-OAuthClient.yaml