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.1.0 RC3 Feature Release

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

Apereo CAS 6.1.x - Credential Caching & Proxy AuthN

Learn how you may configure Apereo CAS to capture and cache the credential's password and the proxy-granting ticket in proxy authentication scenarios, pass them along to applications as regular attributes/claims. We will also be reviewing a handful of attribute release strategies that specifically affect authentication attributes, conveying metadata about the authentication event itself.

Apereo CAS 6.1.x - Attribute Repositories w/ Person Directory

An overview of CAS attribute repositories and strategies on how to fetch attributes from a variety of sources in addition to the authentication source, merge and combine attributes from said sources to ultimately release them to applications with a fair bit of caching.

Apereo CAS 6.1.x - Building CAS Feature Modules

An overview of how various CAS features modules today can be changed and tested from the perspective of a CAS contributor working on the codebase itself to handle a feature request, bug fix, etc.

CAS 6.1.0 RC2 Feature Release

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

Apereo CAS - Riffing on Attribute Release Policies

Learn how to release the kraken of attributes to CAS clients, relying parties and service providers using a variety of attribute release policies and authentication protocols, sampled and collected here to fun and profit.

Apereo CAS - Delegated Authentication to SAML2 Identity Providers

Learn how your Apereo CAS deployment may be configured to delegate authentication to an external SAML2 identity provider.

Apereo CAS - Custom Login Fields w/ Dynamic Bindings

Learn how to extend the Spring Webflow model to add custom fields to the CAS login form and the authentication process and take advantage of the additional user-provided data in customized authentication handlers.

Apereo CAS - SAML2 Identity Provider Integration w/ Gitlab (also staring HAProxy and LDAP)

Learn how Apereo CAS may act as a SAML2 identity provider for Gitlab and run everything locally on a workstation with Docker and Java.

Apereo CAS - Keeping Healthy with Spring Boot

Learn how you may keep your Apereo CAS deployment healthy, monitoring its status using Spring Boot actuator endpoints and health indicators.