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 our 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 Vulnerability Disclosure

Disclosure of a security issue with the CAS software.

CAS Release Notes Moved

CAS Release Notes are moved to the CAS site.

CAS 6.2.0 RC5 Feature Release

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

CAS 6.2.0 RC4 Feature Release

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

CAS 6.2.0 RC3 Feature Release

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

Apereo CAS - Bootiful CAS Client

Easy to use CAS Client

CAS Vulnerability Disclosure

Disclosure of a security issue with the CAS software.

Checking Out Pull Requests Locally

Check out GitHub pull requests as local branches using a simple bash function.

CAS 6.2.0 RC2 Feature Release

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

Apereo CAS - Authentication Handler Resolution

Learn how to resolve and select authentication handlers based on configurable and flexible filtering criteria.