Giter VIP home page Giter VIP logo

php-simple-cas-proxy's Introduction

php-simple-cas-proxy

A very simple CAS proxy. Pass the ticket to other service and proxy the validateService.

Installation

composer require ganlvtech/php-simple-cas-proxy

Usage

Proxy server

<?php
use PhpSimpleCas\PhpCasProxy;

require './vendor/autoload.php';

function service_filter($service_name)
{
    return 0 === strpos($service_name, 'http://cas_client.dev/');
}

$phpCasProxy = new PhpCasProxy('https://cas.dev/');
// $phpCasProxy = new PhpCasProxy('https://cas.dev/', 'service_filter');
// $phpCasProxy = new PhpCasProxy('https://cas.dev/', null, 'http://my_cas.dev/');
// $phpCasProxy = new PhpCasProxy('https://cas.dev/', 'service_filter', 'http://my_cas.dev/', '/cas');
$phpCasProxy->proxy();

// if runs to here, all CAS routes match failed.

Client

jasig/phpcas partly compatible. Only logout, forceAuthentication, checkAuthentication, getUser available.

composer require jasig/phpcas
<?php
require './vendor/autoload.php';
phpCAS::client(CAS_VERSION_2_0, $cas_host, $cas_port, $cas_context);
phpCAS::setNoCasServerValidation();
if (isset($_REQUEST['logout'])) {
    phpCAS::logout();
}
if (isset($_REQUEST['login'])) {
    phpCAS::forceAuthentication();
}
$auth = phpCAS::checkAuthentication();
if ($auth) {
    echo phpCAS::getUser();
} else {
    echo 'Guest mode';
}

About the proxy server

  1. You must login within 5 min, or cookie will be expired, and response may be 403.

  2. Proxy server must use SSL.

  3. Server name and service name may be different.

    $phpCasProxy = new PhpCasProxy('https://cas.dev/', null, 'http://my_cas.dev/');
    $phpCasProxy->proxy();

    must under http://my_cas.dev/ and you can also add a domain https://cas.mydomain.com/ resolved to the same IP.

How to test

Add your service domain to hosts

127.0.0.1 service.example.com
  • You can't use this if you php-cgi is single thread (Try php-fpm or Nginx).

LICENSE

The MIT License (MIT)

Copyright (c) 2017 Ganlv

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

php-simple-cas-proxy's People

Contributors

ganlvtech avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.