justauthme/php-sdk

Official PHP SDK for the JustAuthMe platform

1.1.2 2021-02-21 19:46 UTC

This package is auto-updated.

Last update: 2024-04-22 02:58:19 UTC


README

Contents

  1. Installation
  2. Usage
    1. Instantiate the SDK
    2. Display the login link
      1. Use the default button
      2. Use a custom link
    3. Get user infos from your callback
  3. Complete documentation
  4. Troubleshooting

Installation

composer require justauthme/php-sdk

Usage

1. Instantiate the SDK

<?php

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);

2. Display the login link

2.1 Use the default button (DEPRECATED)

Please see the official button repository for complete documentation: https://github.com/justauthme/button

The generateDefaultButtonHtml method take 2 parameters: lang and size. You can chose between fr and en languages, and between x1, x2 and x4 sizes.

Default lang is en, default size is x2.

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

2.2 Use a custom link

<a href="<?php echo $jamSdk->generateLoginUrl(); ?>">Login with JustAuthMe</a>

3. Get user infos from your callback: redirect_url

<?php

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
     */
}

Complete documentation

For a complete documentation of this SDK, please see DOCUMENTATION.md

Troubleshooting

If anything goes wrong, feel free to open an issue on this repo, we will be pleased to help you.