Coder Social home page Coder Social logo

laravel-saml's Introduction

laravel-saml

Based on laravel-saml (a Laravel 4 project by KnightSwarm).

Open Source SAML Auth Support for Laravel using simplesamlphp.

Requirements

  • Laravel install, of course
  • Working SimpleSAMLphp instance acting like an Service Provider

Installation

First, we need this package available on Laravel, update your composer.json dependencies with:

"mlntn/laravel-saml": "dev-master"

and run composer update

After we have this package, we need to load it on Laravel, for this, add this service provider to the 'providers' array in config/app.php:

'Mlntn\LaravelSaml\LaravelSamlServiceProvider'

and this facade to the 'aliases' array.

'Saml' => 'Mlntn\LaravelSaml\Facades\Saml'

Now, we need to configure it, run the following to create a saml.php file inside config:

 php artisan vendor:publish

You will need to setup routes like this:

Route::post('sso/login', '\Mlntn\LaravelSaml\Controllers\SamlController@login');
Route::post('sso/logout', '\Mlntn\LaravelSaml\Controllers\SamlController@logout');

You will also need to create a service provider class that implements Mlntn\LaravelSaml\Contracts\User and register that class in AppServiceProvider.

Here is an example implementation:

<?php

namespace App\Services;

use App\Models\User;
use Mlntn\LaravelSaml\Contracts\User as UserContract;

class SamlUser implements UserContract {

  /**
   * @param string $identifier
   * @return boolean
   */
  public function exists($identifier) {
    return User::join('user_saml', 'user.id', '=', 'user_id')->whereSamlIdentifier($identifier)->count() > 0;
  }

  /**
   * @param string $identifier
   * @return mixed
   */
  public function get($identifier) {
    return User::select('user.*')->join('user_saml', 'user.id', '=', 'user_id')->whereSamlIdentifier($identifier)->firstOrFail();
  }

  /**
   * @param string $identifier
   * @return mixed
   */
  public function setup($identifier) {
    if (auth()->check()) {
      $user = auth()->user();
      $user->setSamlIdentifier($identifier);
      $user->save();

      return redirect()->intended('/');
    }
    else {
      session()->flash('saml_identifier', $identifier);

      return redirect()->to('/auth/login');
    }
  }

}

laravel-saml's People

Contributors

jaredatrdn avatar mlntn avatar

Watchers

 avatar  avatar

Forkers

nicswan

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.