PHP code example of justauthme / php-sdk

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

    

justauthme / php-sdk example snippets




use JustAuthMe\SDK\JamSdk;

/*
 * Params:
 * @string app_id The app_id provided by the developers console
 * @string redirect_url The callback URL your provided at your app creation
 * @string api_secret The secret delivered to you by the developers console
 */

$jamSdk = new JamSdk($app_id, $redirect_url, $api_secret);

 /* DEPRECATED */ echo $jamSdk->generateDefaultButtonHtml($lang, $size); 



use JustAuthMe\SDK\JamSdk;

if (isset($_GET['access_token'])) {
    // The expected access_token is present

    $jamSdk = new JamSdk($app_id, $redirect_url, $api_secret);
    
    try {
        $user_infos = $jamSdk->getUserInfos($_GET['access_token']);

        /*
         * Everything is fine, you can now register or login the user,
         * depending on the presence in your Database of
         * the provided $user_infos->jam_id
         */
    } catch (Exception $e) {
        error_log($e->getMessage());
        // Login fail, you should redirect to an error page
    }
     
} else {
    /*
     * The callback URL wasn't called with the correct parameter
     * you should redirect to an error page
     */
}
shell script
composer 
html
<a href=" echo $jamSdk->generateLoginUrl();