PHP code example of yowedjamal / bjpass-backend-sdk
1. Go to this page and download the library: Download yowedjamal/bjpass-backend-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/ */
yowedjamal / bjpass-backend-sdk example snippets
use BjPass\Facades\BjPass;
// Créer une URL d'autorisation
$authData = BjPass::createAuthorizationUrl();
// Échanger un code contre des tokens
$result = BjPass::exchangeCode($code, $state);
// Vérifier l'authentification
if (BjPass::isAuthenticated()) {
$user = BjPass::getUserInfo();
}
// Déconnexion
BjPass::logout();
use BjPass\BjPass;
class AuthController extends Controller
{
public function __construct(private BjPass $bjpass) {}
public function login()
{
$authData = $this->bjpass->createAuthorizationUrl();
return redirect()->away($authData['authorization_url']);
}
public function callback(Request $request)
{
$result = $this->bjpass->exchangeCode(
$request->query('code'),
$request->query('state')
);
return response()->json($result);
}
}