mirror of
https://github.com/elyby/accounts.git
synced 2024-07-01 04:33:33 +05:30
Generate keys pair if they aren't exists
This commit is contained in:
parent
967d8b11a0
commit
6ad66b28cf
|
@ -8,6 +8,7 @@ use Exception;
|
||||||
use Lcobucci\JWT\Builder;
|
use Lcobucci\JWT\Builder;
|
||||||
use Lcobucci\JWT\Parser;
|
use Lcobucci\JWT\Parser;
|
||||||
use Lcobucci\JWT\Token;
|
use Lcobucci\JWT\Token;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
use yii\base\Component as BaseComponent;
|
use yii\base\Component as BaseComponent;
|
||||||
|
|
||||||
class Component extends BaseComponent {
|
class Component extends BaseComponent {
|
||||||
|
@ -39,6 +40,13 @@ class Component extends BaseComponent {
|
||||||
*/
|
*/
|
||||||
private $algorithmManager;
|
private $algorithmManager;
|
||||||
|
|
||||||
|
public function init(): void {
|
||||||
|
parent::init();
|
||||||
|
Assert::notEmpty($this->hmacKey, 'hmacKey must be set');
|
||||||
|
Assert::notEmpty($this->privateKeyPath, 'privateKeyPath must be set');
|
||||||
|
Assert::notEmpty($this->publicKeyPath, 'publicKeyPath must be set');
|
||||||
|
}
|
||||||
|
|
||||||
public function create(array $payloads = [], array $headers = []): Token {
|
public function create(array $payloads = [], array $headers = []): Token {
|
||||||
$now = Carbon::now();
|
$now = Carbon::now();
|
||||||
$builder = (new Builder())
|
$builder = (new Builder())
|
||||||
|
|
|
@ -27,6 +27,8 @@ services:
|
||||||
- db
|
- db
|
||||||
- redis
|
- redis
|
||||||
env_file: .env
|
env_file: .env
|
||||||
|
volumes:
|
||||||
|
- certs-storage:/var/www/html/data/certs
|
||||||
networks:
|
networks:
|
||||||
default:
|
default:
|
||||||
aliases:
|
aliases:
|
||||||
|
@ -71,6 +73,14 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- ./data/redis:/data
|
- ./data/redis:/data
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
certs-storage:
|
||||||
|
driver: local
|
||||||
|
driver_opts:
|
||||||
|
type: none
|
||||||
|
device: $PWD/data/certs
|
||||||
|
o: bind
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
nginx-proxy:
|
nginx-proxy:
|
||||||
external:
|
external:
|
||||||
|
|
|
@ -31,6 +31,14 @@ fi
|
||||||
# Fix permissions for cron tasks
|
# Fix permissions for cron tasks
|
||||||
chmod 644 /etc/cron.d/*
|
chmod 644 /etc/cron.d/*
|
||||||
|
|
||||||
|
JWT_PRIVATE_PEM_LOCATION="/var/www/html/data/certs/private.pem"
|
||||||
|
JWT_PUBLIC_PEM_LOCATION="/var/www/html/data/certs/public.pem"
|
||||||
|
if [ ! -f "$JWT_PRIVATE_PEM_LOCATION" ] ; then
|
||||||
|
echo "There is no private key. Generating the new one."
|
||||||
|
openssl ecparam -name prime256v1 -genkey -noout -out "$JWT_PRIVATE_PEM_LOCATION"
|
||||||
|
openssl ec -in "$JWT_PRIVATE_PEM_LOCATION" -pubout -out "$JWT_PUBLIC_PEM_LOCATION"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$1" = "crond" ] ; then
|
if [ "$1" = "crond" ] ; then
|
||||||
# see: https://github.com/dubiousjim/dcron/issues/13
|
# see: https://github.com/dubiousjim/dcron/issues/13
|
||||||
# ignore using `exec` for `dcron` to get another pid instead of `1`
|
# ignore using `exec` for `dcron` to get another pid instead of `1`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user