PHP code example of m7 / iam

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

    

m7 / iam example snippets


      use Illuminate\Foundation\Auth\User as Authenticatable;
      
      class User extends Authenticatable
      {
          use Authenticatable;
      
          protected $fillable = ['iam_uid', 'name', 'surname', 'email', 'password'];
      }
      

    use Illuminate\Foundation\Auth\User as Authenticatable;
    use m7\Iam\Traits\Iam;
    
    class User extends Authenticatable
    {
        use Authenticatable, Iam;
    
        protected $fillable = ['iam_uid', 'name', 'surname', 'email', 'password'];
    }
    

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;
use m7\Iam\Http\Middleware\IamScopes;

class Kernel extends HttpKernel 
{
    ...
    protected $routeMiddleware = [
        ...
        'iam.scopes' => IamScopes::class,
        ...
    ];
    ...
}

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;
use m7\Iam\Http\Middleware\IamAuth;

class Kernel extends HttpKernel 
{
    ...
    protected $routeMiddleware = [
        ...
        'iam.auth' => IamAuth::class,
        ...
    ];
    ...
}

Route::post('iam/login', 'm7\Iam\Http\Controllers\LoginController@login')->name('iam.manager.login');
Route::post('iam/logout', 'm7\Iam\Http\Controllers\LoginController@logout')->name('iam.manager.logout');

Auth::user()->getScopes() // get all scopes assigned to this user
Auth::user()->hasScope($scope) // check if user has certain scope ($scope can also be array, that way you can check if user has multiple scopes)

Route::middleware('iam.scopes:auth.users.manage')->group(function () {
    Route::get('users/manage', function() {
        echo "This route is scope protected";
    });
})

Route::middleware('iam.scopes:auth.users.manage|auth.groups.view')->group(function () {
    Route::get('users/manage', function() {
        echo "This route is scope protected";
    });
})

Route::middleware('iam.auth')->group(function () {
    Route::get('orders', function() {
        echo "This route 

iam_manager()->isUserLoggedIn()

iam_manager()->login($username, $password)

iam_manager()->logout()

iam_manager()->getAccessToken()

iam_manager()->getAccessTokenDecoded()

iam_manager()->getRefreshToken()

iam_manager()->issetValidAccessToken()

iam_manager()->refreshToken()