2017 © Pedro Peláez
 

library dot-authentication

Core interfaces for authentication implementations

image

dotkernel/dot-authentication

Core interfaces for authentication implementations

  • Thursday, April 12, 2018
  • by dotkernel
  • Repository
  • 2 Watchers
  • 1 Stars
  • 680 Installations
  • PHP
  • 7 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 7 % Grown

The README.md

dot-authentication

Authentication base package defining interfaces for authentication services to be used with DotKernel applications., (*1)

OSS Lifecycle PHP from Packagist (specify version), (*2)

GitHub issues GitHub forks GitHub stars GitHub license, (*3)

Build Static codecov, (*4)

SymfonyInsight, (*5)

Installation

Run the following command in you project directory, (*6)

$ composer require dotkernel/dot-authentication

Please note that usually this package will be installed as a dependency to a concrete implementation, so usually you won't need to add this to you project manually., (*7)

AuthenticationInterface

Defines the interface that should be implemented by any authentication service, in order to work with DotKernel applications. This is a result of the fact that the default packages used by DotKernel applications, that need access to the authentication service are type-hinted against this interface., (*8)

Also, concrete implementations should be registered in the service manager using this interface's FQN., (*9)

Methods

public function authenticate(ServerRequestInterface $request): AuthenticationResult;
  • method to implement the actual authentication process. It should extract credentials from the $request object(Authorization header, custom request attributes etc.). It should return an AuthenticationResult object, defined in this package, which carry the authentication status and identity on success.
public function challenge(ServerRequestInterface $request): ResponseInterface;
  • this method should return a valid PSR-7 ResponseInterface used to notify the client or browser that it needs to authenticate first(usually using the WWW-Authenticate header - usefull for HTTP basic and digest authentication)
public function hasIdentity(): bool;
public function getIdentity(): ?IdentityInterface;
public function setIdentity(IdentityInterface $identity);
public function clearIdentity();
  • these methods are used to check if authenticated, get the authenticated identity object, force set an identity(maybe useful for auto-login) or clear an identity(logout)

IdentityInterface

You can use any object to represent an authenticated identity(user) as long as it implements this interface. It requires 2 methods, getId() which should return the unique identifier of the identity, and getName(): string which should return a string representation of the identity(for display purposes, usually the email or username), (*10)

AuthenticationResult

Returned by the authentication service, on authentication success or failure. It composes one of the predefined authentication codes, which describes the authentication status, an error message in case the authentication has failed, and the identity object on success., (*11)

UnauthorizedException

Exception to be thrown when accessing content that need authentication first. This can be used within an application to trigger an error and do a custom action(like redirecting to a login page). There is not a predefined way to handle this, DotKernel packages use this exception paired with a custom error handler to handle unauthorized errors. When using the frontend or admin applications, this is already setup among the authentication/authorization packages, and throwing an UnauthorizedException from anywhere your application, it will redirect to the login page by default., (*12)

The Versions

12/04 2018

dev-master

9999999-dev

Core interfaces for authentication implementations

  Sources   Download

MIT

The Requires

 

The Development Requires

by n3vrax
by DotKernel Team

12/04 2018

1.0.0

1.0.0.0

Core interfaces for authentication implementations

  Sources   Download

MIT

The Requires

 

The Development Requires

by DotKernel Team

12/04 2018

dev-develop

dev-develop

Core interfaces for authentication implementations

  Sources   Download

MIT

The Requires

 

The Development Requires

by n3vrax
by DotKernel Team

10/03 2017

0.1.1

0.1.1.0

Core interfaces for authentication implementations

  Sources   Download

MIT

The Requires

 

The Development Requires

by n3vrax

07/03 2017

0.1.0

0.1.0.0

Core interfaces for authentication implementations

  Sources   Download

MIT

The Requires

 

The Development Requires

by n3vrax