BasicAuth is an authentication scheme built into the HTTP protocol. As long as the client transmits its data over HTTPS, it’s a secure authentication mechanism.
Authorization: Basic YXBpLXVzZXI6c2VjcmV0
The tuupola/slim-basic-auth package implements HTTP Basic Authentication. It was originally developed for Slim but can be used with all frameworks using PSR-7 or PSR-15 style middlewares.
For authorization, you could consider to use OAuth 2.0 in combination with a signed JSON Web Token.
The JWTs can be used as OAuth 2.0 Bearer-Tokens to encode all relevant parts of an access token into the access token itself instead of having to store them in a database.
Please note: OAuth 2.0 is not an authentication protocol.
Clients may use the HTTP Basic authentication scheme, as defined in RFC2617, to authenticate with the server.
After successful authentication, the client sends its token within the
Authorization request header:
Authorization: Bearer RsT5OjbzRn430zqMLgV3Ia
The lcobucci/jwt and firebase/php-jwt packages are a very good tools to work with JSON Web Tokens.
- Slim 4 - Firebase JWT (eBook Vol. 2)
- Slim 4 - Mezzio OAuth2 Server (eBook Vol. 2)
- Slim 4 - JSON Web Token (JWT) (eBook)
- OAuth Libraries for PHP
- Auth0 PHP SDK
- Stop using JWT for sessions
- Swagger - OAuth 2.0
- Slim 4 - SameSite Cookies (eBook Vol. 2)
- Slim 4 - CSRF (eBook Vol. 2)
- Slim Framework CSRF Protection
Cross-Origin Resource Sharing (CORS)
Cross Site Scripting Prevention
Cross-site Scripting (XSS) is a client-side code injection attack. The attacker aims to execute malicious scripts in a web browser of the victim by including malicious code in a legitimate web page or web application.
To prevent XSS you can use an Auto-Escaping Template System such as Twig or by using libraries that are specifically designed to sanitize HTML input: