uxf / security
3.56.3
2024-12-18 10:59 UTC
Requires
- php: ^8.3
- ext-json: *
- firebase/php-jwt: ^6.0
- twig/twig: ^3.0
- uxf/core: 3.56.3
- dev-main
- 3.56.3
- 3.56.2
- 3.56.1
- 3.56.0
- 3.55.9
- 3.55.8
- 3.55.7
- 3.55.5
- 3.55.0
- 3.54.5
- 3.54.3
- 3.54.2
- 3.54.0
- 3.53.7
- 3.53.3
- 3.53.2
- 3.53.1
- 3.53.0
- 3.51.2
- 3.51.0
- 3.50.6
- 3.50.5
- 3.50.3
- 3.50.2
- 3.50.1
- 3.50.0
- 3.49.2
- 3.49.1
- 3.49.0
- 3.48.0
- 3.47.2
- 3.47.0
- 3.46.11
- 3.45.3
- 3.45.2
- 3.45.1
- 3.44.6
- 3.44.5
- 3.44.4
- 3.44.3
- 3.44.2
- 3.44.0
- 3.43.2
- 3.43.0
- 3.42.0
- 3.41.2
- 3.41.1
- 3.41.0
- 3.40.4
- 3.40.3
- 3.40.2
- 3.40.1
- 3.40.0
- 3.39.4
- 3.39.3
- 3.39.2
- 3.39.1
- 3.38.0
- 3.37.1
- 3.37.0
- 3.36.3
- 3.36.2
- 3.36.0
- 3.35.5
- 3.35.4
- 3.35.2
- 3.34.3
- 3.34.0
- 3.33.0
- 3.32.4
- 3.32.3
- 3.30.1
- 3.29.1
- 3.29.0
- 3.27.3
- 3.26.0
- 3.25.5
- 3.25.4
- 3.24.2
- 3.24.1
- 3.24.0
- 3.23.3
- 3.23.1
- 3.23.0
- 3.22.0
- 3.21.4
- 3.21.3
- 3.21.0
- 3.20.0
- 3.19.4
- 3.19.3
- 3.19.2
- 3.18.0
- 3.17.4
- 3.17.3
- 3.17.1
- 3.17.0
- 3.15.6
- 3.15.5
- 3.13.2
- 3.13.0
- 3.11.3
- 3.11.0
- 3.10.1
- 3.10.0
- 3.9.2
- 3.8.2
- 3.8.1
- 3.8.0
- 3.7.3
- 3.7.1
- 3.7.0
- 3.6.0
- 3.5.0
- 3.4.0
- 3.3.0
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.4
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
This package is auto-updated.
Last update: 2024-12-18 10:03:54 UTC
README
Install
$ composer req uxf/security
// config/packages/uxf.php
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->extension('uxf_security', [
'user_class' => User::class, // required
'base_url' => 'https://uxf.cz', // required
'public_key' => '%env(AUTH_PUBLIC_KEY)%', // required
'private_key' => '%env(AUTH_PRIVATE_KEY)%', // required
// optional
'access_token_lifetime' => 'P10Y', // default 1 day
'refresh_token_lifetime' => 'P20Y', // default 1 month
'refresh_token_cookie_path' => '/', // default null (suggestion: /api/auth/refresh-token)
'cookie_name' => 'Cookie-Name', // default Authorization - used for header + cookie
'cookie_secured' => false, // default true
'cookie_http_only' => false, // default true
// OpenID Connect - optional
'oidc' => [
'apple' => [
'client_id' => 'xxx',
],
'facebook' => [
'client_id' => 'xxx',
'client_secret' => 'xxx',
],
'gitlab' => [
'client_id' => 'xxx',
'client_secret' => 'xxx',
],
'google' => [
'client_id' => 'xxx',
],
'microsoft' => [
'client_id' => 'xxx',
],
'mojeid' => [
'client_id' => 'xxx',
],
],
]);
};
OpenID Connect
Create new user
use Nette\Utils\Random;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use UXF\CMS\Entity\User;
use UXF\Security\Service\OIDC\NewUserEvent;
class NewUserEventSubscriber implements EventSubscriberInterface
{
public function process(NewUserEvent $event): void
{
$event->user = new User($event->oidcInfo->email, '', Random::generate());
}
/**
* @inheritDoc
*/
public static function getSubscribedEvents(): array
{
return [
NewUserEvent::class => 'process',
];
}
}
Info about login
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use UXF\Security\Service\OIDC\PreLoginUserEvent;
class PreLoginUserEventSubscriber implements EventSubscriberInterface
{
/**
* @throws OIDCFlowException
*/
public function pre(PreLoginUserEvent $event): void
{
...
}
/**
* @inheritDoc
*/
public static function getSubscribedEvents(): array
{
return [
PreLoginUserEvent::class => 'pre',
];
}
}
Info about connect
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use UXF\Security\Service\OIDC\PreLoginUserEvent;
class PostConnectUserEventSubscriber implements EventSubscriberInterface
{
/**
* @throws OIDCFlowException
*/
public function post(PostConnectUserEvent $event): void
{
...
}
/**
* @inheritDoc
*/
public static function getSubscribedEvents(): array
{
return [
PostConnectUserEvent::class => 'post',
];
}
}
Info about new ExternalLogin
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use UXF\Security\Service\OIDC\NewExternalLoginEvent;
class ExternalLoginEventSubscriber implements EventSubscriberInterface
{
/**
* @throws OIDCFlowException
*/
public function pre(PreNewExternalLoginEvent $event): void
{
...
}
/**
* @throws OIDCFlowException
*/
public function post(PostNewExternalLoginEvent $event): void
{
...
}
/**
* @inheritDoc
*/
public static function getSubscribedEvents(): array
{
return [
PreExternalLoginEvent::class => 'pre',
PostExternalLoginEvent::class => 'post',
];
}
}
Providers & URLs
# login
https://domain.com/api/auth/oidc/<provider>/login
# login with redirect (default is /)
https://domain.com/api/auth/oidc/<provider>/login?redirect=/some-path
# login callback
https://domain.com/api/auth/oidc/<provider>/callback
# connect
https://domain.com/api/auth/oidc/<provider>/connect
# connect with redirect (default is /)
https://domain.com/api/auth/oidc/<provider>/connect?redirect=/some-path
# connect callback
https://domain.com/api/auth/oidc/<provider>/connect-callback