PHP code example of ktakayama / swa

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

    

ktakayama / swa example snippets


$code = ...
$redirect_uri = ...

$key = <<<EOT
-----BEGIN PRIVATE KEY-----
YOUR PRIVATE KEY
-----END PRIVATE KEY-----
EOT;

$token = (new \SWA\TokenBuilder())
        ->setPrivateKey($key)
        ->setKid(YOUR_KEY_ID)
        ->setIss(YOUR_TEAM_ID)
        ->setIat(time())
        ->setExp(time()+3600)
        ->setSub(YOUR_CLIENT_ID);

$authorization = (new \SWA\Reuest($token))->getAuthorizationCode($code, $redirect_uri);
$refresh_token = $authorization->getRefreshToken();
$email = $authorization->getIdToken()->getPayload()->getEmail();

$response = (new \SWA\Reuest($token))->getAccessToken($refresh_token);
$access_token = $response->getAccessToken();

echo $email . "\n";
echo $access_token . "\n";