Apereo CAS as an OAuth2 Authorization Server

The blog is managed and hosted on GitHub. If you wish to update the contents of this post or if you have found an inaccuracy and wish to make corrections, we recommend that you please submit a pull request to this repository.


Apereo CAS can authenticate users in many ways, including by delegating to other authentication providers, and it can get attributes about those users from many places, and finally it can communicate that identity along with those attributes to applications (aka services) via various protocols such as the CAS Protocol, SAML, and OpenID Connect.


In this blog post we are going describe how to configure CAS server to act as Oauth2 authorization server as well as how to set up a sample Spring Boot based web app acting as an Oauth2 client, delegating to CAS to do authentication transactions using authorization_code grant type as well as code response type.

The starting position is based on the following:

  • CAS 6.1.0-RC1 overlay
  • CAS Oauth2 sample client web app
  • Java 11 for CAS server
  • Java 8 to run client app
  • Edit /etc/hosts with: casoauth.example.org

where is replaced with the main IP address of your workstation.

CAS server set up

In your standard CAS 6 overlay project (we’re going to use Gradle-based one), add the following module in build.gradle:

compile "org.apereo.cas:cas-server-support-oauth-webflow:${project.'cas.version'}"

Add OAuth2 registered service representing out client application to CAS’ service registry (we’re using JSON one with hjson syntax flavor):

  @class : org.apereo.cas.support.oauth.services.OAuthRegisteredService
  clientId: exampleOauthClient
  clientSecret: exampleOauthClientSecret
  serviceId: ^https://casoauth.example.org:9999/.*
  name: OAuthService
  id: 1000
  supportedGrantTypes: [ "java.util.HashSet", [ "authorization_code" ] ]
  supportedResponseTypes: [ "java.util.HashSet", [ "code" ] ]

Note the clientId and clientSecret values are significant here as we’ll use those in the client app configuration

Oauth2 client web application set up

Download/clone CAS Oauth2 client sample web app

Modify oauth2 configuration section like so src/main/resources/application.yml:

      clientId: exampleOauthClient
      clientSecret: exampleOauthClientSecret
      accessTokenUri: https://casoauth.example.org:8443/cas/oauth2.0/accessToken
      userAuthorizationUri: https://casoauth.example.org:8443/cas/oauth2.0/authorize
      clientAuthenticationScheme: form
      userInfoUri: https://casoauth.example.org:8443/cas/oauth2.0/profile
      preferTokenInfo: false

Run server and client

On JDK 11, build and run CAS server as per usual e.g. using java -jar ... Make sure it starts on the default port of 8443. Switch to JDK 8 and build and run sample app by invoking ./run.sh from the root of its directory structure.

Then visit https://casauth.example.org:9999/dashboard/login and watch redirect to CAS, login and redirect back using OAuth2 “protocol dance” with authorization_code grant type and code response type.

For more info on other OAuth2 flow types, see the documentation page


Hopefully this helped you learn about how to set up CAS’s support for Oauth2 authorization server as well as integrate Oauth2 client application with it.

Dmitriy Kopylenko

Related Posts

CAS 6.2.0 RC1 Feature Release

...in which I present an overview of CAS 6.2.0 RC1 release.

Apereo CAS - Simple Multifactor Authentication

Learn to configure Apereo CAS to act as a simple multifactor provider itself.

Apereo CAS 2019 Survey Results

...in which I present a summarized view of the latest CAS community survey.

CAS 6.1.0 RC6 Feature Release

...in which I present an overview of CAS 6.1.0 RC6 release.

Apereo CAS - Managing Services via Git

Learn to configure Apereo CAS to fetch application policy files and service records for its service registry from remote git repositories.

Apereo CAS - Ticket Distribution with JMS

Learn to configure Apereo CAS to JMS and messages queues to broadcast tickets and tokens across a deployment cluster.

CAS Vulnerability Disclosure

Disclosure of a security issue with the CAS software.

Apereo CAS - SMS Notifications via Twilio

Learn to configure Apereo CAS for SMS notifications via Twilio.

CAS 6.1.0 RC5 Feature Release

...in which I present an overview of CAS 6.1.0 RC5 release.

Apereo CAS - Passwordless Authentication

Learn how to modify Apereo CAS to allow users to login without the need to remember a password.