PHPackages                             lotashinski/apikey-security-classes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. lotashinski/apikey-security-classes

ActiveLibrary[Security](/categories/security)

lotashinski/apikey-security-classes
===================================

6.0.7(3y ago)065proprietaryPHPPHP &gt;=8.1.0

Since Dec 3Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Lotashinski/apikey-classes)[ Packagist](https://packagist.org/packages/lotashinski/apikey-security-classes)[ Docs](https://github.com/Lotashinski/saml-apikey-classes)[ RSS](/packages/lotashinski-apikey-security-classes/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (7)Dependencies (3)Versions (10)Used By (0)

Installation
------------

[](#installation)

---

Install the latest version with

```
$ composer require lotashinski/apikey-security-classes
```

Usage
-----

[](#usage)

---

### 1. Create users file:

[](#1-create-users-file)

```
## ./config/service/api_keys.yaml or other

users:

  - user_name: api_admin
    roles: [ 'ROLE_USER', 'ROLE_ADMIN' ]
    api_key: qwerty123
    ips:
      - 127.0.0.1

  - user_name: api_user
    roles: [ 'ROLE_USER' ]
    api_key: bbb123
    # if the directive 'ips' is not specified, then it is available from any
```

### 2. Configure dependency injection

[](#2-configure-dependency-injection)

```
## ./config/services.yaml

services:

  Grsu\ApiKeySecurity\ApiKeyAuthentication:
    # arguments:
    #   $strictVerification: false # if there is no need to check every request
    #   $header: X-AUTH-KEY        # if you need to change secure header
    # for create logger tag
    tags:
      - { name: monolog.logger, channel: ApiKeyAuthenticator }

  Grsu\ApiKeySecurity\ApiKeyUserProvider:
    arguments:
      # path to users file
      $pathToUsersConfig: '%kernel.project_dir%/config/service/api_keys.yaml'
    tags:
      - { name: monolog.logger, channel: ApiKeyUserProvider }
```

### 3. Configure security

[](#3-configure-security)

```
### ./config/packages/security.yaml

security:

  # ...
  providers:
    # ...
    api_key_user_provider:
      id: Grsu\ApiKeySecurity\ApiKeyUserProvider

  # ...
  firewalls:
    # ...
    api_key:
      pattern: ^/api/int
      lazy: true
      provider: api_key_user_provider
      custom_authenticator: Grsu\ApiKeySecurity\ApiKeyAuthentication

  # ...
  access_control:
    - { path: ^/api/int, roles: IS_AUTHENTICATED_FULLY }
```

Example
-------

[](#example)

```
