PHP code example of sso-frappe / laravel

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

    

sso-frappe / laravel example snippets


use Laravel\Socialite\Facades\Socialite;

Route::get('/auth/frappe', fn () => Socialite::driver('frappe')->redirect());

Route::get('/auth/frappe/callback', function () {
    $frappeUser = Socialite::driver('frappe')->user();

    // Cocokkan user lokal via provider_subject dulu, fallback email.
});

use SsoFrappe\Laravel\FrappeClient;

$client = app(FrappeClient::class);
$url = $client->authorizationUrl($state, $codeChallenge);
$token = $client->exchangeCode($code, $codeVerifier);
$profile = $client->getUserByToken($token['access_token']);
$user = $client->mapUser($profile);