GithubHelp home page GithubHelp logo

auth's Introduction

Baka Auth

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',
    ],
],

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)) {
        //user
        if (!$user = Users::getByEmail($data['email'])) {
            throw new Exception('User not found');
        }

        //status
        if (!$user->status) {
            throw new Exception('User not active');
        }
        
        return Sessions::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/

ENV

//AUTH
AUTH_COOKIE_NAME=
AUTH_COOKIE_PATH=
AUTH_COOKIE_DOMAIN=
AUTH_COOKIE_SECURE=
AUTH_ALLOW_AUTOLOGIN=
AUTH_SESSION_LENGHT=
AUTH_MAX_AUTOLOGIN_TIME=
AUTH_MAX_AUTOLOGIN_ATTEMPS=
PAGE_INDEX=0
SESSION_METHOD_COOKIE=100
SESSION_METHOD_GET=101
ANONYMOUS=0

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 %}

auth's People

Contributors

kaioken avatar josuegrullon avatar rwhite27 avatar

Stargazers

Karina Rodriguez Herrera avatar

Watchers

James Cloos avatar Danny Feliz avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.