PHP code example of nue-extensions / sso-samarinda

1. Go to this page and download the library: Download nue-extensions/sso-samarinda library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nue-extensions / sso-samarinda example snippets


'extensions' => [

	'sso-samarinda' => [
		// Arahkan kemana Anda akan tuju setelah login berhasil
		'redirect_to' => '/home', 

		// Pilih guard auth default yang dipakai
		'guard' => 'web', 

		// Beberapa parameter yang dibutuhkan untuk broker. Bisa ditemukan di 
		// https://sso.samarindakota.go.id
		'server_url' => env('SSO_SERVER_URL', null),
		'broker_name' => env('SSO_BROKER_NAME', null),
		'broker_secret' => env('SSO_BROKER_SECRET', null),

		// Tentukan Model User yang dipakai
		'model' => '\App\Models\User'
	],
	
],



namespace App\Http\Middleware;

use Nue\SSOSamarinda\Http\Middleware\SSOAutoLogin as Middleware;
use App\Models\User;

class SSOAutoLogin extends Middleware
{
    /**
     * Manage your users models as your default credentials
     *
     * @param Broker $response
     * @return \Illuminate\Http\RedirectResponse
     */
    public function handleLogin($response)
    {
        $user = User::updateOrCreate(['uid' => $response['data']['id']], [
            'name' => $response['data']['name'], 
            'email' => $response['data']['email'], 
            'password' => 'default', 
        ]);

        auth()->login($user);

        return;
    }
}

protected $middlewareGroups = [
    'web' => [
        ...
        // \Nue\SSOSamarinda\Http\Middleware\SSOAutoLogin::class,
        \App\Http\Middleware\SSOAutoLogin::class,
    ],

    'api' => [
        ...
    ],
];

protected function attemptLogin(Request $request)
{
    $broker = new \Nue\SSOSamarinda\Service\Broker;
    
    $credentials = $this->credentials($request);
    return $broker->login($credentials['username'], $credentials['password']);
}

public function logout(Request $request)
{
    $broker = new \Nue\SSOSamarinda\Service\Broker;
    $broker->logout();
    
    $this->guard()->logout();
    $request->session()->invalidate();
    
    return redirect('/');
}
bash
php artisan migrate --path=vendor/nue-extensions/sso-samarinda/database/migrations/2014_10_12_000000_alter_users_table.php
shell
$ php artisan make:middleware SSOAutoLogin