Download the PHP package tag/iu-cas without Composer

On this page you can find all versions of the php package tag/iu-cas. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package iu-cas

Travis-CI build status

IuCasAuthentication

A CAS authentication object that works with CAS @ IU. Using CAS at IU isn't complicated, and UITS even provides some sample code for PHP. 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 standards. Requires PHP >= 7.1. Tested against PHP v7.1 – v7.3

Installation

The preferred method of installation is with Composer.

Install with Composer

Add the following to your composer.json file:

Or, install the Composer package:

Install without Composer

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

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. Defaults to 'IU'.
    • An optional third argument is a reference to a 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

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.

Recommended method

Rather than relying on the built-in behavior, pass explicit callback functions for authentication failure or success.

The two callbacks are:

  1. On Failure: Defaults to setting a "401 Unauthorized" header and exit;.
  2. On Success: Defaults to putting the user name returned from CAS in $_SESSION and returning.

Manage login and validation manually

Although the #authenticate() function does all of the work for you, it's possible to manage the authentication process manually if you wish.

Example with login and validation on different pages in your app

You might use this example code to only implement CAS authentication at a specific URL. Instead of calling #authenticate(), you might do the following:

Slim Framework example

The following code would work with the Slim Framework. This example also uses a PSR-3 logger and anonymous callback functions. The login functionality would be better implemented as Middleware, but this example highlights some features of the IuCasAuthentication helper.

Logging

You may pass an optional PSR-3 logger as the third parameter of the constructor. If the validation step fails, details are sent to the logger, if available.

Environment variables

In most cases, it is not necessary to create environment variables to modify the default behavior of this library for use with CAS at IU. Everything should already work without additional configuration. However, if you wish to change the default behavior, several environment variables are available.

Best practice in PHP is to put important configuration options in environment variables, perhaps in your virtual host configuration (e.g., httpd.conf or .htacess) or in a .env file. Several libraries are available via Composer to assit in loading .env files.

The three necessary URLs (login, validation, logout) as described by https://kb.iu.edu/d/atfc are included by default but may be overridden through the use of the following environment variables.

Two additional environment variables are used:

If storing authentication status somewhere other than the session variable, it's probably best to use the callback variation of #authenticate().

Each of these environment variable defaults is also available as a class constant. e.g., IuCasAuthentication::CAS_VALIDATION_URL. (Exception: Timeout constant is named IuCasAuthentication::CAS_DEFAULT_TIMEOUT.)

Release history


All versions of iu-cas with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tag/iu-cas contains the following files

Loading the files please wait ....