Entity Models

You must specify endpoints for SSOfy to be able to access the necessary resources as needed since it is a no-store service (i.e., it doesn't internally store or cache any data received from resource server or client).

In order to facilitate creating responses for those endpoints, SDK included entity models for the resources.

use SSOfy\Models\Entities\ClientEntity;
...
$client = new ClientEntity([
    'id'                 => 'my-web-app', // required
    'name'               => 'My App Name', // required
    'secret'             => 'CLIENT SECRET KEY',
    'redirect_uris'      => ['*'], // wildcard is supported but not recommended.
    'icon'               => 'https://example.com/icon.png',
    'theme'              => 'default',
    'tos'                => 'https://example.com/tos',
    'privacy_policy'     => 'https://example.com/privacy-policy',
    'confidential'       => true,
]);

// set/modify attributes 
$client->theme = 'default-dark';
$client->confidential = false;
$client->addRedirectUri('https://example.com/callback');

return $client->toArray();
use SSOfy\Models\Entities\ScopeEntity;
...
$scopes = [
    [
        'id'          => '*',
        'title'       => 'Read and Write all data.',
        'description' => null,
        'icon'        => 'fa-id-card',
        'url'         => null,
    ],
    [
        'id'          => 'profile',
        'title'       => 'Your profile information including name, birthday.',
        'description' => 'Click <a href="https://example.com/profile-privacy">here</a> to read more about the data privacy.',
        'icon'        => 'fa-id-card',
        'url'         => null,
    ],
];

return array_map(function($scope) {
    return ScopeEntity::make($scope)->toArray();
}, $scopes);
use SSOfy\Models\Entities\UserEntity;
...
$user = new UserEntity([
    'id'           => '1', //required
    'hash'         => '1', //required
    'display_name' => 'j.walsh@example.com',
    'name'         => 'Jessica Walsh',
    'picture'      => 'https://i.pravatar.cc/48',
    'profile'      => 'https://example.com/profile?id=1',
    'email'        => 'j.walsh@example.com',
    'phone'        => '+441234567890',
    'additional'   => [
        'gender'  => 'Female',
        'country' => 'UK',
    ],
]);

return $user->toArray();
use SSOfy\Models\Entities\UserEntity;
...
$otpOption = new OTPOptionEntity([
    'id'      => 'user1-authorization-email-j.walsh@example.com', //required
    'type'    => 'email', //required
    'to'      => 'j.walsh@example.com', //required
    'hint'    => 'j*****h@*****le.com', //required
    'user_id' => 'user1', //required
    'action'  => 'authorization', //required
]);

return $otpOption->toArray();
use SSOfy\Models\Entities\TokenEntity;
...
$token = new TokenEntity([
    'token' => 'sKmR4BOoaS7bKkKD16uzX71syKLESft4', //required
    'ttl'   => 60 * 60, //required
]);

return $token->toArray();
use SSOfy\Models\Entities\AuthResponseEntity;
...
$authResponse = new AuthResponseEntity([
    'user'  => $authenticatedUser, //required
    'token' => $generatedPasswordlessToken,
]);

return $authResponse->toArray();
use SSOfy\Models\Entities\AuthResponseEntity;
...
$authResponse = new AuthResponseEntity([
    'user'  => $authenticatedUser, //required
    'token' => $generatedPasswordlessToken,
]);

return $authResponse->toArray();
use SSOfy\Models\Entities\PaginatedResponseEntity;
...
$response = new PaginatedResponseEntity([
    'data'  => $result,
    'page' => 1,
    'page_size' => 1,
    'total_pages' => 1,
    'total_count' => 1
]);

return $response->toArray();
ssofyKnowledge Base
At our core, we believe that staying up-to-date with the latest trends and advancements in Authentication and related areas is essential. That's why we take great pride in keeping you informed with the latest insights, updates, and news in this rapidly evolving landscape.


Do you need support?
SSOfy is by Cubelet Ltd.
Copyright © 2024 Cubelet Ltd. All rights reserved.