This library has been developed to interact with cymatic.io backend. This includes such operations as:
- Get access token from SSO
- Register a user on Cymatic
- Verify a user on Cymatic
- Open a session for a user on Cymatic
- Close a session for a user on Cymatic
There's few steps that you need to perform before start using API:
- Make sure user database has field
c_uuidon table - Create new table or environment variables to store cymatic credentials with fields
tenant:StringclientId:Stringsecret:String
- Make sure server allows cymaticsecurity origins ( CORS )
sdk.cymaticsecurity.comrtp.cymaticsecurity.com
- Make sure to have php installed at least version 7.x
- Make sure you have composer installed
It is very recommended to store your access token in cache rather than request it every time for making further calls.
You can use caching library of your choice:
composer.json
{
"require": {
"cymaticsecurity/php-client": "*"
}
}Run installation in your project folder:
php composer.phar installWhen developing client and classes structure changed - don't forget to:
php composer.phar dump-autoloadIf you did not setup autoload in your php project yet, you can do it as follows:
require_once __DIR__ . '/vendor/autoload.php';Use library from namespace:
use Cymatic\Client;
use Cymatic\Cache;Instantiate client:
$client = new Client(
'your tenant',
'your clientId',
'your clientSecret'
);You can change SSO and API urls using these methods:
$client->setAPIUrl('api url');
$client->setSSOUrl('sso url');In different systems timeouts can be painful, so you have method to set default timeouts:
// 10 seconds timeout
$client->setTimeout(10);These are brief examples of how to setup caching framework:
$client->setCache(new Cache(Cache::$CACHE_TYPE_MEMCACHED, array('127.0.0.1', 11211)));
$client->setCache(new Cache(Cache::$CACHE_TYPE_REDIS, array('127.0.0.1', 6379)));
$client->setCache(new Cache(Cache::$CACHE_TYPE_APC));There is no option to setup multiply servers for caching, if you need this feature please request it or make pull request to our official repository.
To ask for an access token against Cymatic SSO the requirements are:
tenanton the URIclientIdandclientSecretas Basic Base64 encoded on the Headergrant_typeasclient_credentialson the form payload
Request
POST https://sso.cymaticsecurity.com/auth/realms/{{tenant}}/protocol/openid-connect/token/
Headers
"Authorization": "Basic base64(${clientId}:${clientSecret})"
Body
{
"grant_type": "client_credentials"
}
It is done automatically once you doing any API request, so you don't need to care about this step yourself.
To register a user on Cymatic the requirements are:
Access JWT tokenon the header asAuthorization BearerContent-Typeasapplication/jsonon the headerAliasfor new user on the body payloadIdentity JWTfrom the Browser on the body payload
Request
POST https://api.cymaticsecurity.com/profiles
Headers
"Authorization": "Bearer JWT.from.SSO"
"Content-Type": "application/json"
Body
{
"alias": "some alias",
"jwt": "JWT.from.Browser"
}
$sdkJWT = $_POST['cy/jwt'];
$alias = $_POST['email'];
$registration = $client->register($sdkJWT, $alias);
echo 'Registration: ' . json_encode($registration);When registration is done, save $registration['c_uuid'] in your database.
This is user unique identifier in cymatic which you will use for all future calls.
To verify a user against Cymatic the requirements are:
Access JWT tokenon the header asAuthorization BearerContent-Typeasapplication/jsonon the headerc_uuidfrom the user attempting to log inIdentity JWTfrom the Browser on the body payload
Request
POST https://api.cymaticsecurity.com/verify
Headers
"Authorization": "Bearer JWT.from.SSO"
"Content-Type": "application/json"
Body
{
"c_uuid": "Id provided by cymatic",
"jwt": "JWT.from.Browser"
}
$c_uuid = $registration['c_uuid'];
$verification = $client->verify($sdkJWT, $c_uuid);
echo 'Verification: ' . json_encode($verification);Verification response contains all necessary information for you to make decision about further user login behavior. You can block user, allow him access or make challenge if you have such recommendations in response.
This is typical verification response:
{
"TODO": "TODO"
}To open a session for user against Cymatic the requirements are:
Access JWTtoken on the header asAuthorization BearerContent-Typeasapplication/jsonon the headerc_uuidfrom the user attempting to log inIdentity JWTfrom the Browser on the body payload
Request
POST https://api.cymaticsecurity.com/login
Headers
"Authorization": "Bearer JWT.from.SSO"
"Content-Type": application/json"
Body
{
"c_uuid": "Id provided by cymatic",
"jwt": "JWT.from.Browser"
}
$session = $client->login($sdkJWT, $c_uuid);
echo 'Session: ' . json_encode($session);To close a session for user against Cymatic the requirements are:
Access JWT tokenon the header asAuthorization BearerContent-Typeasapplication/jsonon the headerc_uuidfrom the user attempting to log in
Request
POST https://api.cymaticsecurity.com/logout
Headers
"Authorization": "Bearer JWT.from.SSO"
"Content-Type": "application/json"
Body
{
"c_uuid": "Id provided by cymatic",
"session_id": "Session ID"
}
$session_id = $login['session_id'];
$client->logout($session_id, $c_uuid);MIT
© Cymatic Team