PHP code example of misakstvanu / laravel-zsso-client
1. Go to this page and download the library: Download misakstvanu/laravel-zsso-client 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/ */
misakstvanu / laravel-zsso-client example snippets
use Illuminate\Contracts\Auth\Authenticatable;
use Misakstvanu\ZssoClient\Contracts\ProvisionsSsoUser;
use Misakstvanu\ZssoClient\Exceptions\ProvisioningDeniedException;
use Misakstvanu\ZssoClient\SsoUser;
class ProvisionUser implements ProvisionsSsoUser
{
public function provision(SsoUser $user): Authenticatable
{
if (! $user->emailVerified) {
// Back to `login_path` with the message flashed as `error`.
throw new ProvisioningDeniedException('Nejdřív si ověř e-mail v zSSO.');
}
return User::updateOrCreate(
['zsso_sub' => $user->sub],
['name' => $user->name, 'email' => $user->email],
);
}
}
// AppServiceProvider::register()
$this->app->bind(ProvisionsSsoUser::class, ProvisionUser::class);
use Misakstvanu\ZssoClient\Events\SsoLoginCompleted;
use Misakstvanu\ZssoClient\Facades\Zsso;
class HydrateSkautisSession
{
public function handle(SsoLoginCompleted $event): void
{
if ($event->ssoUser->skautis === null) {
return;
}
Zsso::skautis($event->user)->session()?->applyTo(app(\Skautis\Skautis::class));
}
}
use Misakstvanu\ZssoClient\Facades\Zsso;
$token = Zsso::tokenFor($user); // a live access token
use Misakstvanu\ZssoClient\Facades\Zsso;
$session = Zsso::skautis($user)->session(); // ?SkautisSessionData
$session?->applyTo($skautis); // hydrate a \Skautis\Skautis client
Zsso::skautis($user)->refresh(); // SkautIS keep-alive
Zsso::skautis($user)->switchRole(679); // activate another role
Zsso::skautis($user)->logout(); // end the SkautIS login
use Misakstvanu\ZssoClient\IntegrationContext;
$context = IntegrationContext::current();
$context->callerSlug; // 'zirafa'
$context->actingUserSub; // the zSSO uuid from X-Zsso-Acting-User, or null
$context->actsForUser(); // whether the caller named one
use Misakstvanu\ZssoClient\Facades\Zsso;
Zsso::webhook('zirafa.attendee.upserted', ['attendee_id' => $attendee->id])->to('zskauting');
// or to every app that receives webhooks, this one excluded
Zsso::webhook('zirafa.attendee.upserted', ['attendee_id' => $attendee->id])->toAll();