PHP code example of univicosa / laravel-openid-client

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

    

univicosa / laravel-openid-client example snippets


protected function unauthenticated($request, AuthenticationException $exception) : \Illuminate\Http\RedirectResponse
{
     if ($request->expectsJson()) {
         return response()->json(['error' => 'Unauthenticated.'], 401);
     }
     
     if (env('APP_ENV') === 'local') {
         return redirect()->guest(route('login'));
     }

     return redirect()->guest(config('openid.server') . '/login?continue=' . $request->url());
}

#### APP CONFIG ####
APP_URL=url-project (https://domain.com)

#### CACHE CONFIG ####
BROADCAST_DRIVER=log
CACHE_DRIVER=redis
SESSION_DRIVER=file
SESSION_LIFETIME=240
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

#### OAUTH OPENID ####
AUTH_SERVER=https://oauth.univicosa.com.br or https://devauth.univicosa.com.br
CLIENT_ID=you-client-id
CLIENT_SECRET=your-secret-code

protected $routeMiddleware = [
   'auth' => \Illuminate\Auth\Middleware\Authenticate::class // CHANGE THIS
]; 

'guards' => [
    'web' => [
        'driver' => 'openid',
        'provider' => NULL,
    ],
    /*
     * ...
     */
]

@method \Oauth2::getSystems(): array
@api GET '/api/{version}/system'

@return array With Systems available in Oauth Server

@method \Oauth2::getSystemRoles(): array
@api GET '/api/{version}/system/roles'

@return array With System givable roles

@method \Oauth2::getSystemPermissions(): array
@api GET '/api/{version}/system/permissions'

@return array With System givable permissions

@method \Oauth2::getUser(): array
@api GET '/api/{version}/user'

@return array With logged user data

@method \Oauth2::getUserProfiles(): array
@api GET '/api/{version}/profile'

@return array With logged user profiles

@method \Oauth2::getUserByCpf(string $cpf): array
@api POST '/api/{version}/user/cpf'

@return array With the data of user owner of document given

@method \Oauth2::getUsersByCpf(array $cpf): array
@api POST '/api/{version}/user/search/cpf'

@return array With the data of user owner of document given: limit array size to 100 items

@method \Oauth2::searchUserByName(string $name): array
@api POST '/api/{version}/user/name'

@return array With the data of users owner of document given

@method \Oauth2::searchUserByRegistry(string $registry): array
@api POST '/api/{version}/user/registry'

@return array With the data of users owner of registry given

@method \Oauth2::getUserSystems(): array
@api GET '/api/{version}/user/systems'

@return array With the systems that the user is allowed to access

@method \Oauth2::getUserPermissions(): array
@api GET '/api/{version}/user/permissions'

@return array With the roles that the logged user has in the request owner

@method \Oauth2::getGenders(): array
@api GET '/api/{version}/profile/genders'

@return array With th data of all genders available for select on the Oauth Server

@method \Oauth2::setUserPermission(string $cpf, string $role, string $expires_at = ''): array
@api POST '/api/{version}/user/permission'

@return array with the response of Post action

@method \Oauth2::isAddressFilled(): array
@api GET '/api/{version}/address/filled'

@return array With the Boolean response if the user address data is populated on the Oauth Server

@method \Oauth2::getStates(): array
@api GET '/api/{version}/address/states'

@return array With the data of all Brazilian states present on the Oauth Server

@method \Oauth2::getCities(string $state): array
@api GET '/api/{version}/address/cities/{state}'

@return array With the data of all Brazilian cities according to the state given present on the Oauth Server

@method \Oauth2::setAddress(array $data): array
@api POST '/api/{version}/address'

@return array with the response of Post action

@method \Oauth2::setProfile(array $data): array
@api POST '/api/{version}/profile'

@return array with the response of Post action

@method \Oauth2::setUsername(array $data): array
@api POST '/api/{version}/user/update/username'

@return array with the response of Post action

@method \Oauth2::getUsersType(string $type): array
@api POST '/api/{version}/profile/users/type'

@return array With all user data available for a type selected on the Oauth server

@method \Oauth2::setUsersType(array $data): array
@api POST '/api/{version}/profile/create/usertype'

@return array with the response of Post action

@method \Oauth2::removeAllTypesFromUser(array $data): array
@api POST '/api/{version}/profile/remove/usertype'

@return array with the response of Post action

config('openid.server') . '{ouath_service_page}?' . http_build_query(['continue' => {route_to_redirect_back}])

php artisan vendor:publish --tag=openid-config