baka / auth
Baka Component for user authentification
Installs: 7 834
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 6
Forks: 3
Open Issues: 3
Requires
- php: >=7.2
- ext-phalcon: >=3.0.0
- baka/database: ^0.5
- baka/http: ^0.5
- lcobucci/jwt: ^3.2
- phalcon/incubator: ~3.0
- vlucas/phpdotenv: ^2.0
Requires (Dev)
- dev-master
- 0.5.x-dev
- 0.2.x-dev
- v0.2.5.5
- v0.2.5.4
- 0.2.5.3
- v0.2.5.2
- v0.2.5.1
- v0.2.5
- v0.2.4
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2
- 0.1.x-dev
- v0.1.7
- v0.1.6
- 0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1
- dev-add-scrutinizer-0.2
- dev-fix-link-source-uniqueness
- dev-fix-dependencies
- dev-feature-upgrade-to-baka-0.5
- dev-hotfix-users-index
This package is auto-updated.
Last update: 2025-01-29 06:19:19 UTC
README
MC Auth Library to avoid having to redo a user signup flow for apps.
Testing
codecept run
JWT
Add JWT to your configuration
'jwt' => [ 'secretKey' => getenv('JWT_SECURITY_HASH'), 'expirationTime' => '1 hour', #strtotime 'payload' => [ 'exp' => 1440, 'iss' => 'phalcon-jwt-auth', ], 'ignoreUri' => [ 'regex:auth', 'regex:webhook', 'regex:/users', ], ],
Database
We use phinx for migration , to update this project db structure just run
vendor/bin/phinx-migrations generate
To run this migration from your project just add the path of the db location to your phinx.php path
<?php
return [
'paths' => [
'migrations' => [
getenv('PHINX_CONFIG_DIR') . '/db/migrations',
'/home/baka/auth/db/migrations',
],
vendor/bin/phinx migrate -e (enviorment : development | production)
Using
Add this to your service.php
/** * UserData dependency injection for the system * * @return Session */ $di->set('userData', function () use ($config, $auth) { $data = $auth->data(); $session = new Baka\Auth\Models\Sessions(); $request = new Phalcon\Http\Request(); if (!empty($data) && !empty($data['sessionId'])) { //user if (!$user = Baka\Auth\Models\Users::getByEmail($data['email'])) { throw new Exception('User not found'); } return $session->check($user, $data['sessionId'], $request->getClientAddress(), 1); } else { throw new Exception('User not found'); } });
Generate migration files
$ phalcon migration --action=run --migrations=migrations --config=</path/to/config.php>
Import migration into project
$ phalcon migration --action=run --migrations=vendor/baka/auth/migrations/
Router
$router->post('/auth', [ '\Your\NameSpace\AuthController', 'login', ]); $router->post('/auth/signup', [ '\Your\NameSpace\AuthController', 'signup', ]); $router->post('/auth/logout', [ '\Your\NameSpace\AuthController', 'logout', ]); # get email for new password $router->post('/auth/recover', [ '\Your\NameSpace\AuthController', 'recover', ]); # update new password $router->put('/auth/{key}/reset', [ '\Your\NameSpace\AuthController', 'reset', ]); # active the account $router->put('/auth/{key}/activate', [ '\Your\NameSpace\AuthController', 'activate', ]);
Social logins
"hybridauth/hybridauth": "dev-3.0.0-Remake",
<?php 'social_config' => [ // required "callback" => getenv('SOCIAL_CONNECT_URL'), // required "providers" => [ "Facebook" => [ "enabled" => true, "callback" => getenv('SOCIAL_CONNECT_URL').'/Facebook', "keys" => ["id" => getenv('FB_ID'), "secret" => getenv('FB_SECRET')], //production ] ], ],
And configure the links and callback link (SOCIAL_CONNECT_URL) to http://site.com/users/social/{site} Example: http://site.com/users/social/Facebook
You need to add this to your registration process to idenfity social login
{% if socialConnect %} <input type="hidden" name="socialConnect" value="1"> {% endif %}