Set up authentication to make API calls to Virgil ServicesThis guide shows how to set up authentication using Access Token.In order to make call to Virgil Services (for example, to publish user's Card on Virgil Cards Service), you need to have a Access Token. You have to generate for each Application an Access Token on Virgil Dashboard.Prerequisites for workInstall SDK and Setup Virgil CryptoThe Virgil SDK is provided as a package named virgil/sdk. The package is distributed via composer package management system.You need to install php virgil crypto extension ext-virgil_crypto_php as one of dependency otherwise you will get the requested PHP extension virgil_crypto_php is missing from your system error during composer install.In general to install virgil crypto extension follow next steps:Download proper extension package for your platform from cdn like virgil-crypto-2.0.4-php-5.6-linux-x86_64.tgz.Type following command to unpack extension in terminal:$ tar -xvzf virgil-crypto-2.0.4-php-5.6-linux-x86_64.tgzPlace unpacked virgil_crypto_php.so under php extension path.Add virgil extension to your php.ini configuration file like extension = virgil_crypto_php.so.$ echo "extension=virgil_crypto_php.so" >> \ `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`All necessary information about where php.ini or extension_dir are you can get from php_info() in case run php on server or call php -i | grep php.ini or php -i | grep extension_dir from CLI.Prerequisites:PHP 5.6.*Composervirgil_crypto_php.soInstalling the package:$ composer require virgil/sdkCollect your Virgil developer credentialsParameterDescriptionAPP_IDID of your Application at Virgil DashboardAPP_KEYA Private Key that is used to sign users' Cards. For security, you will only be shown the App Private Key when the key is created. Don't forget to save it in a secure location for the next stepAPP_KEY_PASSWORDA password to your APP KEY ACCESS_TOKENAn unique string that is used to authorize requests on Virgil Services.You generate an Access Token on developer dashboard and then provide the Token to a user. With the Token, the user can then safely communicate with the Virgil Services.The user first signs into your Application server using the authentication server’s login system (e.g. username and password, Facebook login, Google login, etc). The Application server then sends Token to the user. When the user makes API calls to the Virgil Cards Service, the user passes the Token along with the API call. The Cards Service is configured to verify that the incoming Token is given by the Application server. So, when the user makes API calls with the attached Access Token, Virgil can use the Token to verify that the API call is coming from an authenticated user.Each Access Token is granted access to specific Application and has permissions that are configured by you.Let's see how we can set up authentication:first, we'll set up a client sidesecond, we'll set up a server side with your Virgil account credentialsSet up Client sideWhen users want to start sending and receiving messages in a browser or mobile device, Virgil can't trust them right away. Clients have to be provided with a unique identity, thus, you'll need to give your users the Access Token that tells Virgil who they are and what they can do.Each your client must send to you the Access Token request with their registration request. Then, your service that will be responsible for handling access requests must handle them in case of users successful registration on your Application server.here an example of an Access Token// an example of an Access Token representation AT.7652ee415726a1f43c7206e4b4bc67ac935b53781f5b43a92540e8aae5381b14Use an Access TokenWith the Access Token we can initialize the Virgil SDK on the client-side to start doing fun stuff like sending and receiving messages.To initialize the Virgil SDK on a client-side you need to use the following code:$virgilApi = VirgilApi::create('[YOUR_ACCESS_TOKEN_HERE]');Requests to your app server must be authorized. You can use any kind of authentication, for example, Google auth.Set up Server SideNext, you'll set up server-side SDK to sign and approve user's Card.Here is an example of how to setup server side with an Access Token:$virgilApiContext = VirgilApiContext::create( [ VirgilApiContext::AccessToken => '[YOUR_ACCESS_TOKEN_HERE]', VirgilApiContext::Credentials => new AppCredentials( '[YOUR_APP_ID_HERE]', Buffer::fromBase64('[YOUR_APP_PRIVATE_KEY_HERE]'), '[YOUR_APP_PRIVATE_KEY_PASS_HERE]' ), ] ); $virgilApi = new VirgilApi($virgilApiContext);It is important to understand that the purpose of using Token is NOT to hide or obscure data in any way. The reason why Token is used is to prove that the sent data was actually created by an authentic source.