PHP code example of uisits / laravel-oidc

1. Go to this page and download the library: Download uisits/laravel-oidc 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/ */

    

uisits / laravel-oidc example snippets


> In AuthServiceProvider:
> Gate::define('admin', function (User $user) {
>    return $user->hasRole('admin');
> });
> 
> To check if user is admin you can either use:
> User::find()->hasRole
> 
> OR
> 
> Gate::allows('admin')
> 

use UisIts\Oidc\Http\Controllers\AuthController;

Route::name('login')->get('login', [AuthController::class, 'login']);

Route::name('callback')->get('/auth/callback', [AuthController::class, 'callback']);

Route::name('logout')->get('/logout', [AuthController::class, 'logout']);

    use Spatie\Permission\Traits\HasRoles;
    class User extends Authenticatable
    {
        use HasRoles;
    }
    

    # In AuthServiceProvider
    Gate::define('admin', function (User $user) {
        return $user->hasRole('admin');
    });
    # OR
    $user->hasRole('admin');
  

'introspect' => \UisIts\Oidc\Http\Middleware\Introspect::class,

use UisIts\Oidc\Http\Middleware\Introspect;

Route::middleware(['introspect'])->get('/introspect', function (Request $request) {
    dump($request->bearerToken());
    dd(Introspect::getUserFromToken($request->bearerToken()));
})->name('introspect');

Introspect::getUserFromToken($request->bearerToken());

array:8 [▼ // routes/api.php:24
  "sub" => "[email protected]"
  "uisedu_is_member_of" => array:42 [▶]
  "uisedu_uin" => "123456789"
  "preferred_username" => "xyz"
  "given_name" => "John"
  "preferred_display_name" => "Doe, John"
  "family_name" => "Doe"
  "email" => "[email protected]"
];
 php artisan shibboleth:install