Coder Social home page Coder Social logo

usercomponent's Introduction

User component

This component provides some tools for user management.

Features

Installation

composer require biig/user

usercomponent's People

Contributors

babeou avatar nek- avatar awkan avatar

Watchers

 avatar James Cloos avatar  avatar Mark LUCAS avatar Manuel BARRAUD avatar  avatar  avatar  avatar Céline Morin avatar

Forkers

nek- bponchaux

usercomponent's Issues

Update documentation

The README & documentation isn't friendly enough, we should add some sentences to explain it more nicely

[RFC] Make easier configuration of basic auth

This component is supposed to help you bootstrap a project with basic auth. But it only provides a guard that supports basic authentication.

We need to add this controller and its route:

public function __construct(JwtGeneratorInterface $generateJwtTokenForAuthentication, AuthenticationSuccessHandlerInterface $authenticationSuccessHandler)
{
    $this->generateJwtTokenForAuthentication = $generateJwtTokenForAuthentication;
    $this->authenticationSuccessHandler      = $authenticationSuccessHandler;
}

public function __invoke()
{
    $user = $this->getUser();

    $user->setLoginAt(new \DateTimeImmutable());
    $user->setToken($this->generateJwtTokenForAuthentication->create($user));

    $response        = $this->authenticationSuccessHandler->handleAuthenticationSuccess($user, $user->getToken());
    $decodedResponse = json_decode($response->getContent(), true);
    $user->setRefreshToken($decodedResponse['refresh_token']);

    return $user;
}

This controller (and some other classes of this package) needs a JwtGenerator that the user must define. No doc about (#1) and weird errors. Here is an example of implementation.

class StandardJwtGenerator implements JwtGeneratorInterface
{
    /**
     * @var JWTEncoderInterface
     */
    private $encoder;

    /**
     * @var string|\DateTime
     */
    private $expiration;

    /**
     * GenerateJwtTokenForAuthentication constructor.
     *
     * @param JWTEncoderInterface $encoder
     */
    public function __construct(JWTEncoderInterface $encoder, $expiration = '+1 day')
    {
        $this->encoder    = $encoder;
        $this->expiration = $expiration;
    }

    /**
     * @param UserInterface $user
     *
     * @return string
     */
    public function create(UserInterface $user)
    {
        $expiration = $this->expiration;
        if (!$expiration instanceof \DateTimeInterface) {
            $expiration = new \DateTime($this->expiration);
        }

        $payload = [
            'id'    => $user->getId(),
            'email' => $user->getEmail(),
            'exp'   => $expiration->getTimestamp(),
        ];

        return $this->encoder->encode($payload);
    }
}

Aliasing interfaces is also required:

services:
    Biig\Component\User\Jwt\JwtGeneratorInterface: '@App\Domain\User\Security\StandardJwtGenerator'
    Biig\Component\User\Persistence\RepositoryInterface: '@App\Infrastructure\ORM\User\Repository\UserRepository'

This is a problem because it removes the possibility to have many services within the interface. It should be done via configuration and automatic creation of services.

This is absolutely not documented. And it could be added automatically by the bundle with a little line of configuration... That modifies the behavior of the guard which is a little bit too much hardcoded. See here:

return 1 === \preg_match('/login$/', $request->getPathInfo()) && $this->isAllowedRequest($request);

So, to summarize here is what to do:

  1. Add the given controller
  2. Add a way of configuration to enable service and controller (basic auth to start)
  3. Document this

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.