Giter Club home page Giter Club logo

laravel-onelogin's Introduction

THIS PACKAGE HAS MOVED

This package has moved to https://github.com/ziffmedia/laravel-onelogin

Furthermore, the new package has reached 1.0, production worthy status and should be used in place of any application where ziffdavis/laravel-onelogin was once used.

Laravel onelogin

A Laravel package for allowing onelogin to provide authentication and users to your application. This library wraps onelogin's onelogin/php-saml library.

Features:

  • simplified configuration process
  • top level (configurable) login and logout routes
  • support for autologin
  • ability to map any User attributes via a login event
  • loose SAML workflow for localhost/local environments, strict when in production

Installation

composer require ziffdavis/laravel-onelogin

Next, publish the configuration file:

artisan vendor:publish --provider='ZiffDavis\Laravel\Onelogin\OneloginServiceProvider'

Note for Laravel 5.7+

If your application uses Laravel 5.7 or greater, please make sure this package is updated to v0.0.7 or greater.

Configuration & Setup

Go into your onelogin administration screen, create an application with the "SAML Test Connector (IdP w/attr)" template. The onelogin tutorial is a great reference at https://developers.onelogin.com/saml/php

Once you have an app in onelogin minimally setup, utilize the App > SSO tab to get the necessary values to put inside the configuration file. See ./config/onelogin.php for details on which fields are necessary.

The User Setup

(The following setup assumes your users will be populated by onelogin the first time they successfully try to log into your application.)

Out the box, this package is designed to work with the typical user schema provided with laravel with minimal changes. Typical changes to make look like this:

  • remove the 2014_10_12_100000_create_password_resets_table.php migration file
  • remove the $table->timestamp('email_verified_at')->nullable(); and $table->string('password'); columns from the 2014_10_12_000000_create_users_table.php migration

(Optional) Laravel Nova...

Laravel Nova's default installation adds authentication routes to your application, it is wise to remove them inside your application's NovaServiceProvider:

    /**
     * Register the Nova routes.
     *
     * @return void
     */
    protected function routes()
    {
        Nova::routes()
                // ->withAuthenticationRoutes()
                // ->withPasswordResetRoutes()
                ->register();
    }

User Attributes and New User Workflow

By default, the following actions happen on successful login (From the OneloginController):

    protected function resolveUser(array $userAttributes)
    {
        $userClass = config('auth.providers.users.model');

        $user = $userClass::firstOrNew(['email' => $credentials['User.email'][0]]);

        if (isset($credentials['User.FirstName'][0]) && isset($credentials['User.LastName'][0])) {
            $user->name = "{$credentials['User.FirstName'][0]} {$credentials['User.LastName'][0]}";
        }

        $user->save();

        return $user;
    }

To customize this experience, create an Event inside your applications EventServiceProvider's boot() method:

    public function boot()
    {
          // assuming: use ZiffDavis\Laravel\Onelogin\Events\OneloginLoginEvent;
          
          Event::listen(OneloginLoginEvent::class, function (OneloginLoginEvent $event) {
              $user = User::firstOrNew(['email' => $event->userAttributes['User.email'][0]]);
  
              if (isset($event->userAttributes['User.FirstName'][0]) && isset($event->userAttributes['User.LastName'][0])) {
                  $user->name = "{$event->userAttributes['User.FirstName'][0]} {$event->userAttributes['User.LastName'][0]}";
              }
              
              // other custom logic here
  
              $user->save();
  
              return $user;
          });
    }

laravel-onelogin's People

Contributors

ralphschindler avatar jimbojsb avatar recycledbeans avatar

Stargazers

Tom Shaw avatar  avatar Filipe Garcia avatar  avatar  avatar

Watchers

Chris Kite avatar  avatar Cooper Sellers avatar Dennis Heckman avatar David Moore avatar James Cloos avatar  avatar Swetha Lingala avatar Seton Brown avatar Alex Cavalli avatar Kristen  Burroughs avatar Erik W. Marshall avatar James Ratcliff avatar  avatar Lee Pulatie avatar James Pappas avatar  avatar  avatar Saad Hussain avatar  avatar Tristan avatar  avatar Eric Fischbein avatar Gary Newcomb avatar

laravel-onelogin's Issues

Deprecation Notice: PSR-4 and Composer 2.0

Hi, I'm getting a deprecation notice when installing via composer:

Deprecation Notice: Class ZiffDavis\Laravel\Onelogin\Controllers\OneLoginController located in ./vendor/ziffdavis/laravel-onelogin/src/Controllers/OneloginController.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///usr/local/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:201

Package Installation

Hello, I'm kinda new with laravel nova. Could you please tell me step by step how to implement this on laravel nova ? thanks.

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.