Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .laminas-ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ignore_php_platform_requirements": {
"8.4": true
},
"backwardCompatibilityCheck": true
}
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 DotKernel
Copyright (c) 2016 Dotkernel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
33 changes: 20 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# dot-authentication

Authentication base package defining interfaces for authentication services to be used with DotKernel applications.
Authentication base package defining interfaces for authentication services to be used with Dotkernel applications.

![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-authentication)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-authentication/2.3.4)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-authentication/2.5.0)

[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/issues)
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/network)
Expand All @@ -13,21 +13,20 @@ Authentication base package defining interfaces for authentication services to b
[![Build Static](https://github.com/dotkernel/dot-authentication/actions/workflows/continuous-integration.yml/badge.svg?branch=2.0)](https://github.com/dotkernel/dot-authentication/actions/workflows/continuous-integration.yml)
[![codecov](https://codecov.io/gh/dotkernel/dot-authentication/graph/badge.svg?token=ZBZDEA3LY8)](https://codecov.io/gh/dotkernel/dot-authentication)

[![SymfonyInsight](https://insight.symfony.com/projects/8a0dfa12-fdda-43d7-bdbe-1c6996b30c12/big.svg)](https://insight.symfony.com/projects/8a0dfa12-fdda-43d7-bdbe-1c6996b30c12)

## Installation

Run the following command in you project directory

```bash
$ composer require dotkernel/dot-authentication
```shell
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.

## 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.
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.

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

Expand All @@ -37,13 +36,16 @@ Also, concrete implementations should be registered in the service manager using
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.
This method is the implementation of 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.

```php
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)
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 - useful for HTTP basic and digest authentication).

```php
public function hasIdentity(): bool;
Expand All @@ -52,16 +54,21 @@ 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)
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)
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).

## 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.
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.

## 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.
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.
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
"license": "MIT",
"authors": [
{
"name": "DotKernel Team",
"name": "Dotkernel Team",
"email": "team@dotkernel.com"
}
],
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0",
"psr/http-message": "^1.0 || ^2.0"
},
"require-dev": {
"laminas/laminas-coding-standard": "^3.0",
"phpunit/phpunit": "^10.2",
"laminas/laminas-coding-standard": "^2.5",
"vimeo/psalm": "^5.13"
},
"autoload": {
Expand All @@ -38,7 +38,8 @@
"scripts": {
"check": [
"@cs-check",
"@test"
"@test",
"@static-analysis"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
Expand Down
1 change: 0 additions & 1 deletion docs/book/index.md

This file was deleted.

1 change: 1 addition & 0 deletions docs/book/index.md
4 changes: 3 additions & 1 deletion docs/book/v2/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

Install `dot-authentication` by executing the following Composer command:

composer require dotkernel/dot-authentication
```shell
composer require dotkernel/dot-authentication
```
2 changes: 1 addition & 1 deletion docs/book/v2/overview.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Overview

`dot-authentication` is DotKernel's authentication base package which define interfaces for authentication services to be used with DotKernel applications.
`dot-authentication` is Dotkernel's authentication base package which define interfaces for authentication services to be used with Dotkernel applications.
23 changes: 16 additions & 7 deletions docs/book/v2/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## 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.
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.

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

Expand All @@ -12,13 +13,16 @@ Also, concrete implementations should be registered in the service manager using
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.
This method is the implementation of 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.

```php
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)
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)

```php
public function hasIdentity(): bool;
Expand All @@ -27,16 +31,21 @@ 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)
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)
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)

## 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.
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.

## 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.
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.