PHPackages                             hagmann/zf-oauth2-doctrine - 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. [Database &amp; ORM](/categories/database)
4. /
5. hagmann/zf-oauth2-doctrine

ActiveLibrary[Database &amp; ORM](/categories/database)

hagmann/zf-oauth2-doctrine
==========================

Doctrine OAuth2 Server Adapter for Apigility

1.0.2(10y ago)017BSD-3-ClausePHPPHP &gt;=5.5

Since Apr 13Pushed 10y ago1 watchersCompare

[ Source](https://github.com/hagmann/zf-oauth2-doctrine)[ Packagist](https://packagist.org/packages/hagmann/zf-oauth2-doctrine)[ RSS](/packages/hagmann-zf-oauth2-doctrine/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (17)Versions (22)Used By (0)

OAuth2 Doctrine Adapter for Apigility
=====================================

[](#oauth2-doctrine-adapter-for-apigility)

[![Build Status](https://camo.githubusercontent.com/2b8e6266d2834ab468332d30d84c07fea0b9d1cf12935f10c11873d575a71e05/68747470733a2f2f7472617669732d63692e6f72672f4150492d536b656c65746f6e732f7a662d6f61757468322d646f637472696e652e737667)](https://travis-ci.org/API-Skeletons/zf-oauth2-doctrine)[![Total Downloads](https://camo.githubusercontent.com/67332c310f83095ca043c2f3e8dc84a8a10960b4cad87864bb231cc8768ab6c4/68747470733a2f2f706f7365722e707567782e6f72672f6170692d736b656c65746f6e732f7a662d6f61757468322d646f637472696e652f646f776e6c6f616473)](https://packagist.org/packages/api-skeletons/zf-oauth2-doctrine)

About
-----

[](#about)

This provides a Doctrine adapter for [zfcampus/zf-mvc-auth](https://github.com/zfcampus/zf-oauth2)and entity definitions for all aspects of OAuth2 including Authorization Code, Access Tokens, Refresh Tokens, JWT &amp; JTI, and Scopes.

[![Entity Relationship Diagram](https://raw.githubusercontent.com/API-Skeletons/zf-oauth2-doctrine/master/media/oauth2-doctrine-erd.png)](https://raw.githubusercontent.com/API-Skeletons/zf-oauth2-doctrine/master/media/oauth2-doctrine-erd.png)Entity Relationship Diagram created with [Skipper](https://skipper18.com)

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

[](#installation)

Installation of this module uses composer. For composer documentation, please refer to [getcomposer.org](http://getcomposer.org/).

```
$ php composer.phar require api-skeletons/zf-oauth2-doctrine "^1.0"
```

Add this module to your application's configuration:

```
'modules' => [
   ...
   'ZF\OAuth2\Doctrine',
],
```

The User Entity
---------------

[](#the-user-entity)

This repository supplies every entity you need to implement OAuth2 except the User entity. The reason is so the User entity can be decoupled from the OAuth2 Doctrine repository instead to be linked dynamically at run time. This allows, among other benefits, the ability to create an ERD without modifying the `OAuth2-orm.module.xml` module.

The User entity must implement `ZF\OAuth2\Doctrine\Entity\UserInterface`

The User entity for the unit test for this module is a good template to start from:

Module Configuration
--------------------

[](#module-configuration)

Copy `config/oauth2.doctrine-orm.global.php.dist` to your autoload directory and rename to `oauth2.doctrine-orm.global.php` This config has multiple sections for multiple adapters. Out of the box this module provides a `default` adapter. You will need to edit this file with at least your User entity, which is not provided.

Configuration With zfcampus/zf-mvc-auth
---------------------------------------

[](#configuration-with-zfcampuszf-mvc-auth)

By default this module includes a `oauth2.doctrineadapter.default` adapter. The adapter is used to create storage from services:

```
    'zf-mvc-auth' => array(
        'authentication' => array(
            'adapters' => array(
                'oauth2_doctrine' => array(
                    'adapter' => 'ZF\\MvcAuth\\Authentication\\OAuth2Adapter',
                    'storage' => array(
                        'storage' => 'oauth2.doctrineadapter.default',
                        'route' => '/oauth',
                    ),
                ),
            ),
        ),
    ),
```

Configuration with zfcampus/zf-oauth2
-------------------------------------

[](#configuration-with-zfcampuszf-oauth2)

Add the default storage adapter to the zf-oauth default storage:

```
'zf-oauth2' => array(
    'storage' => 'oauth2.doctrineadapter.default',
```

It is possible to use this library with a second set of entities for a second OAuth2 server in the same application using two or more APIs.

Using Default Entities
----------------------

[](#using-default-entities)

Details for creating your database with the included entities are outside the scope of this project. Generally this is done through [doctrine/doctrine-orm-module](https://github.com/doctrine/DoctrineORMModule)with `php public/index.php orm:schema-tool:create`

By default this module uses the entities provided but you may use the adapter with your own entites (and map them in the mapping config section) by toggling this flag:

```
'zf-oauth2-doctrine' => [
    'default' => [
        'enable_default_entities' => true,
```

Customizing Many to One Mapping
-------------------------------

[](#customizing-many-to-one-mapping)

If you need to customize the call to mapManyToOne, which creates the dynamic joins to the User entity from the default entites, you may add any parameters to the `['dynamic_mapping']['default_entity']['additional_mapping_data']` element. An example for a User entity with a primary key of user\_id which does not conform to the metadata naming strategy is added to each entity:

```
'refresh_token_entity' => [
    'entity' => 'ZF\OAuth2\Doctrine\Entity\RefreshToken',
    'field' => 'refreshToken',
    'additional_mapping_data' => [
        'joinColumns' => [
            [
                'name' => 'user_id',
                'referencedColumnName' => 'user_id',
            ],
        ],
    ],
],
```

Identity field on User entity
-----------------------------

[](#identity-field-on-user-entity)

By default this Doctrine adapter retrieves the user by the `username` field on the configured User entity. If you need to use a different or multiple fields you may do so via the 'auth\_identity\_fields' key. For example, ZfcUser allows users to authenticate by username and/or email fields.

An example to match ZfcUser `auth_identity_fields` configuration:

```
'zf-oauth2-doctrine' => [
    'default' => [
        'auth_identity_fields' => ['username', 'email'],
```

Validate zf-apigility-doctrine resources
----------------------------------------

[](#validate-zf-apigility-doctrine-resources)

To validate the OAuth2 session with Query Create Filters and Query Providers implement `ZF\OAuth2\Doctrine\OAuth2ServerInterface` and use `ZF\OAuth2\Doctrine\OAuth2ServerTrait`. Then call `$result = $this->validateOAuth2($scope);` in the filter function.

Extensions
----------

[](#extensions)

Other module(s) which extend the functionality this repository provides.

- [api-skeletons/zf-oauth2-doctrine-console](https://github.com/API-Skeletons/zf-oauth2-doctrine-console) - Console management of a default zf-oauth2-doctrine installation.
- [basz/zf-oauth2-doctrine-mutabletablenames](https://github.com/basz/zf-oauth2-doctrine-mutatetablenames) - If you do not want to use the default table names provided with the default entities this module lets you customize them.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 83.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~16 days

Recently: every ~52 days

Total

18

Last Release

3779d ago

Major Versions

0.3.5 → 1.0.02015-08-31

PHP version history (2 changes)0.1.0PHP &gt;=5.3.23

1.0.0PHP &gt;=5.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/60ed7a6015a466a2e6698c5f05cc6f79766cef10722381b14d090aa71a1863fa?d=identicon)[hagmann](/maintainers/hagmann)

---

Top Contributors

[![TomHAnderson](https://avatars.githubusercontent.com/u/493920?v=4)](https://github.com/TomHAnderson "TomHAnderson (86 commits)")[![basz](https://avatars.githubusercontent.com/u/143068?v=4)](https://github.com/basz "basz (11 commits)")[![viniciusgava](https://avatars.githubusercontent.com/u/831829?v=4)](https://github.com/viniciusgava "viniciusgava (3 commits)")[![hagmann](https://avatars.githubusercontent.com/u/11349379?v=4)](https://github.com/hagmann "hagmann (2 commits)")[![juizmill](https://avatars.githubusercontent.com/u/1959742?v=4)](https://github.com/juizmill "juizmill (1 commits)")

---

Tags

doctrineoauth2apigility

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/hagmann-zf-oauth2-doctrine/health.svg)

```
[![Health](https://phpackages.com/badges/hagmann-zf-oauth2-doctrine/health.svg)](https://phpackages.com/packages/hagmann-zf-oauth2-doctrine)
```

###  Alternatives

[hounddog/doctrine-data-fixture-module

Zend Framework 2 Module that provides Doctrine Data-Fixture functionality

37335.4k9](/packages/hounddog-doctrine-data-fixture-module)[mamuz/mamuz-blog

Provides blog feature for ZF2 with Doctrine

101.1k1](/packages/mamuz-mamuz-blog)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
