Apereo CAS as an OAuth2 Authorization Server


Collaborate
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.

CAS

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.

Outline

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:
1.2.3.4 casoauth.example.org

where 1.2.3.4 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:

security:
  oauth2:
    client:
      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
    resource:
      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

Finale

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 RC4 Feature Release

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

Apereo CAS - Multifactor Provider Selection

Learn how to configure CAS to integrate with and use multiple multifactor providers at the same time. This post also reveals a few super secret and yet open-source strategies one may use to select appropriate providers for authentication attempts, whether automatically or based on a menu.

Apereo CAS - Dockerized Hazelcast Deployments

Learn how to run CAS backed by a Hazelcast cluster in Docker containers and take advantage of the Hazelcast management center to monitor and observer cluster members.

Apereo CAS - Configuration Security w/ Jasypt

Learn how to secure CAS configuration settings and properties with Jasypt.

CAS 6.1.0 RC3 Feature Release

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

Apereo CAS - Webflow Decorations

Learn how you may decorate the Apereo CAS login webflow to inject data pieces and objects into the processing engine for display purposes, peace on earth and prosperity of all mankind, etc. Mainly, etc.

Apereo CAS - SAML2 Metadata Query Protocol

Learn how you may configure Apereo CAS to fetch and validate SAML2 metadata for service providers from InCommon's MDQ server using the metadata query protocol.

Saving Time is Time Consuming

May you live in the best of times. May you live in the startup times.

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.