PHPackages                             tag/iu-cas - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. tag/iu-cas

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

tag/iu-cas
==========

Authentication class for CAS at IU.

v1.0(7y ago)08MITPHPPHP &gt;=7.1.0

Since Jan 13Pushed 7y ago1 watchersCompare

[ Source](https://github.com/tag/IuCasAuthentication)[ Packagist](https://packagist.org/packages/tag/iu-cas)[ Docs](https://github.com/tag/IuCasAuthentication)[ RSS](/packages/tag-iu-cas/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (4)Versions (7)Used By (0)

[![Travis-CI build status](https://camo.githubusercontent.com/838932cd3032e532f0bf2a25a681a1f2c036ef947175d5e69220cfb4ca9cf3da/68747470733a2f2f7472617669732d63692e636f6d2f7461672f497543617341757468656e7469636174696f6e2e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/838932cd3032e532f0bf2a25a681a1f2c036ef947175d5e69220cfb4ca9cf3da/68747470733a2f2f7472617669732d63692e636f6d2f7461672f497543617341757468656e7469636174696f6e2e7376673f6272616e63683d6d6173746572)

IuCasAuthentication
===================

[](#iucasauthentication)

A CAS authentication object that works with CAS @ IU. Using [CAS at IU](https://kb.iu.edu/d/atfc) isn't complicated, and UITS even provides some [sample code for PHP](https://kb.iu.edu/d/bfru). This helper class aims to make the process even easier.

Note that this library does not provide any *authorization* (permissions based on user name), only *authentication* (verifying a user's credentials).

Follows PSR-4 and [PSR-2](https://github.com/phpstan/phpstan) standards. Requires PHP &gt;= 7.1. Tested against PHP v7.1 – v7.3

Installation
------------

[](#installation)

The preferred method of installation is with [Composer](https://getcomposer.org).

### Install with Composer

[](#install-with-composer)

Add the following to your `composer.json` file:

```
"tag/iu-cas": ">=1.0"

```

Or, install the Composer package:

```
composer require tag/iu-cas

```

### Install without Composer

[](#install-without-composer)

Download the `IuCasAuthentication` class, and include or require it on your page(s).

Using `IuCasAuthentication`
---------------------------

[](#using-iucasauthentication)

1. Create a new authentication object. All arguments to the constructor are optional.

    - The first is the URL if your application that CAS should redirect to after log in. Must be the same during authentication and validation steps. Defaults to the current URL.
    - An optional second argument must be one of the [CAS application codes at IU](https://kb.iu.edu/d/alqm). Defaults to `'IU'`.
    - An optional third argument is a reference to a [PSR-3](https://www.php-fig.org/psr/psr-3/) logger (such as Monolog). Used to log remote errors, if available. Defaults to `null``.
2. Call `#authenticate()`. Optional arguments are avaialable to override default behavior.

Because CAS expects applications to only authenticate once per session, the `IuCasAuthentication` class stores a successful authentication in `$_SESSION`, so it is safe to use on every page (or as Middleware) to test authentication.

If the username is in `$_SESSION`, `#authenticate()` considers the user successfully authenticated, and does not attempt to check against CAS.

### Simplest method

[](#simplest-method)

Let the `IuCasAuthentication` helper do all of the work for you. Requires `$_SESSION` to currently be writable.

This code would need to be called on every page you wish protected.

```
