Skip to content
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #31 from TomHAnderson/hotfix/long-access-token
Browse files Browse the repository at this point in the history
Change AccessToken.accessToken to text to support JWT
  • Loading branch information
TomHAnderson committed May 25, 2015
2 parents 342e30f + 0d8de10 commit 576469c
Show file tree
Hide file tree
Showing 15 changed files with 265 additions and 117 deletions.
17 changes: 16 additions & 1 deletion Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,24 @@
use Zend\ModuleManager\ModuleManager;
use ZF\OAuth2\Doctrine\EventListener\DynamicMappingSubscriber;
use Doctrine\ORM\Mapping\Driver\XmlDriver;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\ConsoleUsageProviderInterface;
use Zend\Console\Adapter\AdapterInterface as Console;

class Module
class Module implements
AutoloaderProviderInterface,
ConfigProviderInterface,
ConsoleUsageProviderInterface
{
public function getConsoleUsage(Console $console)
{
return array(
'oauth2:jwt:create' => 'Create a JWT for a given client',
'oauth2:public-key:create' => 'Create the PublicKey data for a given client',
);
}

public function onBootstrap($e)
{
$app = $e->getParam('application');
Expand Down
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ OAuth2 Doctrine Adapter for Apigility

[![Build Status](https://travis-ci.org/TomHAnderson/zf-oauth2-doctrine.svg?branch=0.1.0)](https://travis-ci.org/TomHAnderson/zf-oauth2-doctrine)
[![Coverage Status](https://coveralls.io/repos/TomHAnderson/zf-oauth2-doctrine/badge.svg)](https://coveralls.io/r/TomHAnderson/zf-oauth2-doctrine)
[![Total Downloads](https://poser.pugx.org/zfcampus/zf-oauth2-doctrine/downloads)](https://packagist.org/packages/zfcampus/zf-oauth2-doctrine)
[![Total Downloads](https://poser.pugx.org/zfcampus/zf-oauth2-doctrine/downloads)](https://packagist.org/packages/zfcampus/zf-oauth2-doctrine)


About
-----

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

![Entity Relationship Diagram](https://github.com/TomHAnderson/zf-oauth2-doctrine/blob/master/media/oauth2-doctrine-erd.png)

Expand All @@ -19,7 +19,7 @@ Installation
Installation of this module uses composer. For composer documentation, please refer to [getcomposer.org](http://getcomposer.org/).

```sh
$ php composer.phar require zfcampus/zf-oauth2-doctrine "~0.2"
$ php composer.phar require zfcampus/zf-oauth2-doctrine "~0.3"
```

Add this module to your application's configuration:
Expand Down Expand Up @@ -51,9 +51,9 @@ The User entity for the unit test for this module is a good template to start fr
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-orm-module with ```php public/index.php orm:schema-tool:create```
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 toggle this and use your own entites (and map them in the mapping config section) by toggling this flag:
By default this module uses the entities provided but you may the adapter with your own entites (and map them in the mapping config section) by toggling this flag:

```php
'zf-oauth2-doctrine' => array(
Expand Down Expand Up @@ -86,17 +86,28 @@ If you need to customize the call to mapManyToOne, which creates the dynamic joi
Identity field on User entity
-----------------------------

By default the DoctrineAdapter for OAuth2 retrieves the user by 'username' field on the entity. If you need to use a different or multiple fields you can do that via the 'auth_identity_fields' key. For example; ZfcUser allows users to authenticate by username and/or email fields.

example : match ZfcUser `auth_identity_fields` configuration
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:
```php
'zf-oauth2-doctrine' => array(
'storage_settings' => array(
'auth_identity_fields' => array('username', 'email'), // defaults to array('username')
```


Command Line Tools
------------------

To make JWT easier to test command line tools are included.

* `oauth2:jwt:create` Create a new JWT for a given client. This JWT will be used by an oauth2 connection requesting a grant_type of `urn:ietf:params:oauth:grant-type:jwt-bearer`. Creating the JWT puts the oauth2 connection requet's public key in place in the OAuth2 tables.

* `oauth2:public-key:create` Create the public/private key record for the given client. This data is used to sign JWT access tokens. Each client may have only one key pair.

For the connecting side `zf-oauth2-client` provides a command line tool to generate a JWT reqeust. See also http://bshaffer.github.io/oauth2-server-php-docs/grant-types/jwt-bearer/


Extensions
----------

Expand Down
34 changes: 33 additions & 1 deletion config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,40 @@
'ZF\OAuth2\Doctrine\Factory\DoctrineMapperFactory',
),
'factories' => array(
'ZF\OAuth2\Doctrine\Adapter\DoctrineAdapter' =>
'ZF\OAuth2\Doctrine\Adapter\DoctrineAdapter' =>
'ZF\OAuth2\Doctrine\Factory\DoctrineAdapterFactory',
),
),

'controllers' => array(
'invokables' => array(
'ZF\OAuth2\Doctrine\Controller\Jwt' => 'ZF\OAuth2\Doctrine\Controller\JwtController',
'ZF\OAuth2\Doctrine\Controller\PublicKey' => 'ZF\OAuth2\Doctrine\Controller\PublicKeyController',
),
),

'console' => array(
'router' => array(
'routes' => array(
'create-jwt' => array(
'options' => array(
'route' => 'oauth2:jwt:create',
'defaults' => array(
'controller' => 'ZF\OAuth2\Doctrine\Controller\Jwt',
'action' => 'create'
),
),
),
'create-public-key' => array(
'options' => array(
'route' => 'oauth2:public-key:create',
'defaults' => array(
'controller' => 'ZF\OAuth2\Doctrine\Controller\PublicKey',
'action' => 'create'
),
),
),
),
),
),
);
2 changes: 1 addition & 1 deletion config/oauth2.doctrine-orm.global.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ return array(
'access_token' => array(
'type' => 'field',
'name' => 'accessToken',
'datatype' => 'string',
'datatype' => 'text',
),
'expires' => array(
'type' => 'field',
Expand Down
2 changes: 1 addition & 1 deletion config/orm/ZF.OAuth2.Doctrine.Entity.AccessToken.dcm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<id name="id" type="integer">
<generator strategy="AUTO"/>
</id>
<field name="accessToken" type="string" nullable="true"/>
<field name="accessToken" type="text" nullable="true"/>
<field name="expires" type="datetime" nullable="true"/>
<many-to-one field="client" target-entity="ZF\OAuth2\Doctrine\Entity\Client" inversed-by="accessToken">
<join-columns>
Expand Down
2 changes: 1 addition & 1 deletion config/orm/ZF.OAuth2.Doctrine.Entity.Client.dcm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<one-to-many field="authorizationCode" target-entity="ZF\OAuth2\Doctrine\Entity\AuthorizationCode" mapped-by="client"/>
<one-to-many field="jwt" target-entity="ZF\OAuth2\Doctrine\Entity\Jwt" mapped-by="client"/>
<one-to-many field="jti" target-entity="ZF\OAuth2\Doctrine\Entity\Jti" mapped-by="client"/>
<one-to-many field="publicKey" target-entity="ZF\OAuth2\Doctrine\Entity\PublicKey" mapped-by="client"/>
<one-to-one field="publicKey" target-entity="ZF\OAuth2\Doctrine\Entity\PublicKey" mapped-by="client"/>
<many-to-many field="scope" target-entity="ZF\OAuth2\Doctrine\Entity\Scope" mapped-by="client"/>
</entity>
</doctrine-mapping>
6 changes: 3 additions & 3 deletions config/orm/ZF.OAuth2.Doctrine.Entity.PublicKey.dcm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<field name="publicKey" type="text" nullable="true"/>
<field name="privateKey" type="text" nullable="true"/>
<field name="encryptionAlgorithm" type="string" nullable="true"/>
<many-to-one field="client" target-entity="ZF\OAuth2\Doctrine\Entity\Client" inversed-by="publicKey">
<one-to-one field="client" target-entity="ZF\OAuth2\Doctrine\Entity\Client" inversed-by="publicKey">
<join-columns>
<join-column name="client_id" referenced-column-name="id" nullable="false" on-delete="CASCADE"/>
<join-column name="client_id" referenced-column-name="id" nullable="false" unique="true" on-delete="CASCADE"/>
</join-columns>
</many-to-one>
</one-to-one>
</entity>
</doctrine-mapping>
35 changes: 18 additions & 17 deletions media/OAuth2-orm.module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@
<many-to-many-field from="access_token_id" to="id"/>
</many-to-many-entity>
</many-to-many>
<region namespace="\ZF\OAuth2\Doctrine\Entity" caption="Tokens" uuid="2842966b-796c-48f0-920e-74b0fc40ec24">
<region namespace="\ZF\OAuth2\Doctrine\Entity" caption="Token" uuid="2842966b-796c-48f0-920e-74b0fc40ec24">
<entity name="\ZF\OAuth2\Doctrine\Entity\AccessToken" local-name="AccessToken" namespace="\ZF\OAuth2\Doctrine\Entity" uuid="0cef011b-fcdf-4e6e-a813-2a8d49ba4748">
<field name="id" type="integer" required="true" unique="true" primary="true" auto-increment="true" uuid="b27267d6-52c7-4d23-b414-0dc5cf604105"/>
<field name="accessToken" type="string" uuid="209f4728-d8cc-498b-808f-ecd7b473eaa6"/>
<field name="accessToken" type="text" uuid="209f4728-d8cc-498b-808f-ecd7b473eaa6"/>
<field name="expires" type="datetime" uuid="a1a27c78-6780-4bb9-882a-010170c2ab64"/>
<field name="client_id" type="integer" required="true" uuid="57674c7f-3b8f-4381-b9e4-dfe8d5eb8ca7"/>
<orm-attributes>
Expand Down Expand Up @@ -160,7 +160,7 @@
<field name="publicKey" type="text" uuid="25e4e0a0-f374-462e-acb1-80335f0f995a"/>
<field name="privateKey" type="text" uuid="f20479d1-190f-42da-a99d-214515ccef6a"/>
<field name="encryptionAlgorithm" type="string" uuid="83593e76-ad34-4103-b524-37898567ede8"/>
<field name="client_id" type="integer" required="true" uuid="8bbf535b-14cb-432c-921f-c9cf693db8e2"/>
<field name="client_id" type="integer" required="true" unique="true" uuid="8bbf535b-14cb-432c-921f-c9cf693db8e2"/>
<orm-attributes>
<attribute name="table">PublicKey_OAuth2</attribute>
</orm-attributes>
Expand All @@ -179,40 +179,41 @@
<attribute name="on-delete">CASCADE</attribute>
</orm-attributes>
</association>
<association from="\ZF\OAuth2\Doctrine\Entity\PublicKey" to="\ZF\OAuth2\Doctrine\Entity\Client" owner-alias="publicKey" inverse-alias="client" many-owner="true" many-inverse="false" parent-required="true" uuid="9daca6d8-8f09-4f97-bbfd-6db05bdf3e58">
<association from="\ZF\OAuth2\Doctrine\Entity\PublicKey" to="\ZF\OAuth2\Doctrine\Entity\Client" owner-alias="publicKey" inverse-alias="client" many-owner="false" many-inverse="false" parent-required="true" uuid="9daca6d8-8f09-4f97-bbfd-6db05bdf3e58">
<association-field from="client_id" to="id"/>
<orm-attributes>
<attribute name="on-delete">CASCADE</attribute>
</orm-attributes>
</association>
</module>
<visual-data>
<comment uuid="05a610e1-fad6-4e65-8b59-c09ed14d78bb" bg-color="4294967264" position-x="31" position-y="236" size-x="0" size-x2="198" size-y="0" size-y2="92" txt-color="4278190080"/>
<entity uuid="0cef011b-fcdf-4e6e-a813-2a8d49ba4748" bg-color="4294967295" hdr-color="4292006610" position-x="59" position-y="16" size-x="0" size-x2="106" size-y="0" size-y2="73"/>
<comment uuid="05a610e1-fad6-4e65-8b59-c09ed14d78bb" bg-color="4294967264" position-x="25" position-y="364" size-x="0" size-x2="198" size-y="0" size-y2="92" txt-color="4278190080"/>
<entity uuid="0cef011b-fcdf-4e6e-a813-2a8d49ba4748" bg-color="#FFFFFF" hdr-color="#D2D2D2" position-x="62" position-y="185" size-x="0" size-x2="106" size-y="0" size-y2="73"/>
<entity uuid="0e40a98d-82ec-47f1-acc0-649982b1c48a" bg-color="4294967295" hdr-color="4292006610" position-x="300" position-y="203" size-x="0" size-x2="93" size-y="0" size-y2="87"/>
<many-to-many-association-entity uuid="1a2f2f70-ba2a-49c8-a50c-ffe2206b4013" split="1"/>
<entity uuid="1b40f6a9-e21a-49d3-8d44-604e36d28d35" bg-color="4294967295" hdr-color="4292006610" position-x="60" position-y="124" size-x="0" size-x2="127" size-y="0" size-y2="101"/>
<entity uuid="1b40f6a9-e21a-49d3-8d44-604e36d28d35" bg-color="4294967295" hdr-color="4292006610" position-x="57" position-y="30" size-x="0" size-x2="127" size-y="0" size-y2="101"/>
<many-to-many-association uuid="1d7e8cae-9456-4602-a095-f2048b9303c4" color="4288059030"/>
<many-to-many-association-entity uuid="216d4d0a-a391-4879-ad9e-d195d818dc27" split="1"/>
<region uuid="2842966b-796c-48f0-920e-74b0fc40ec24" bg-color="4293194728" position-x="422" position-y="121" size-x="0" size-x2="225" size-y="0" size-y2="405"/>
<region uuid="2842966b-796c-48f0-920e-74b0fc40ec24" bg-color="#E4F3E8" position-x="422" position-y="121" size-x="0" size-x2="225" size-y="0" size-y2="405"/>
<many-to-many-association-entity uuid="438b279b-99ed-4a90-9352-79845961ace6" split="1"/>
<entity uuid="4f5f9113-1ca7-472d-ba02-7b178329ced8" bg-color="4294967295" hdr-color="4292006610" position-x="173" position-y="350" size-x="0" size-x2="127" size-y="0" size-y2="60"/>
<entity uuid="4f5f9113-1ca7-472d-ba02-7b178329ced8" bg-color="4294967295" hdr-color="4292006610" position-x="27" position-y="191" size-x="0" size-x2="127" size-y="0" size-y2="60"/>
<many-to-many-association-entity uuid="5a9f1849-17bf-4479-9c06-dcd5e1784e90" center-position-x="0" center-position-y="-16"/>
<many-to-many-association uuid="609e9b50-11d4-4ba4-8e4e-37a0286c0358" color="4288059030"/>
<entity uuid="654eac84-7c6d-4280-9138-1658291dfb7e" bg-color="4294967295" hdr-color="4292006610" position-x="24" position-y="253" size-x="0" size-x2="148" size-y="0" size-y2="60"/>
<entity uuid="654eac84-7c6d-4280-9138-1658291dfb7e" bg-color="4294967295" hdr-color="4292006610" position-x="27" position-y="99" size-x="0" size-x2="148" size-y="0" size-y2="60"/>
<comment uuid="664daa50-d4a6-4d82-a35f-5eb5e2e8e7ca" bg-color="4294967264" position-x="39" position-y="5" size-x="0" size-x2="264" size-y="0" size-y2="72" txt-color="4278190080"/>
<many-to-many-association uuid="7563f43f-925d-4df3-bfd3-d2bf1855a0ca" color="4288059030"/>
<entity uuid="8c75fc92-0e0a-43ed-b5dc-5859aba057ae" bg-color="4294967295" hdr-color="4292006610" position-x="72" position-y="306" size-x="0" size-x2="106" size-y="0" size-y2="73"/>
<entity uuid="8c75fc92-0e0a-43ed-b5dc-5859aba057ae" bg-color="4294967295" hdr-color="4292006610" position-x="63" position-y="304" size-x="0" size-x2="106" size-y="0" size-y2="73"/>
<entity uuid="8cc40580-9611-471f-a6c7-9a64ec3b2869" bg-color="4294967295" hdr-color="4292006610" position-x="208" position-y="172" size-x="0" size-x2="99" size-y="0" size-y2="59"/>
<region uuid="98a49ed5-e644-4a4e-9b59-d5421643572a" bg-color="4292931823" position-x="675" position-y="122" size-x="0" size-x2="319" size-y="0" size-y2="424"/>
<entity uuid="9c143447-a1f4-4187-a5f9-45e768f78ebb" bg-color="4294967295" hdr-color="4292006610" position-x="52" position-y="41" size-x="0" size-x2="93" size-y="0" size-y2="73"/>
<entity uuid="b6562bcc-4fca-413e-a560-91da4d75dc9f" bg-color="4294967295" hdr-color="4292006610" position-x="50" position-y="126" size-x="0" size-x2="134" size-y="0" size-y2="87"/>
<entity uuid="d25ad9b3-1751-49e7-901d-a92fae42a8b2" bg-color="4294967295" hdr-color="4292006610" position-x="23" position-y="90" size-x="0" size-x2="127" size-y="0" size-y2="60"/>
<region uuid="98a49ed5-e644-4a4e-9b59-d5421643572a" bg-color="4292931823" position-x="675" position-y="122" size-x="16" size-x2="319" size-y="0" size-y2="404"/>
<entity uuid="9c143447-a1f4-4187-a5f9-45e768f78ebb" bg-color="4294967295" hdr-color="4292006610" position-x="20" position-y="241" size-x="0" size-x2="93" size-y="0" size-y2="73"/>
<entity uuid="b6562bcc-4fca-413e-a560-91da4d75dc9f" bg-color="4294967295" hdr-color="4292006610" position-x="18" position-y="33" size-x="0" size-x2="134" size-y="0" size-y2="87"/>
<entity uuid="d25ad9b3-1751-49e7-901d-a92fae42a8b2" bg-color="4294967295" hdr-color="4292006610" position-x="146" position-y="310" size-x="0" size-x2="127" size-y="0" size-y2="60"/>
<many-to-many-association-entity uuid="d69ad79d-983f-4cda-905f-1e084aefaff1" center-position-x="0" center-position-y="0"/>
<many-to-many-association uuid="d6c88e38-48c1-43d7-b5e9-b6902ee48e7c" color="4288059030"/>
<module uuid="e33a902b-9096-46f4-81af-cb8fa813a736" bg-color="4287552497" size-x="30" size-x2="1020" size-y="32" size-y2="651"/>
<entity uuid="f42aa952-941d-4cec-adaf-5df5bc023867" bg-color="4294967295" hdr-color="4292006610" position-x="58" position-y="357" size-x="0" size-x2="96" size-y="0" size-y2="101"/>
<entity uuid="f42aa952-941d-4cec-adaf-5df5bc023867" bg-color="4294967295" hdr-color="4292006610" position-x="139" position-y="241" size-x="0" size-x2="96" size-y="0" size-y2="101"/>
<many-to-many-association-entity uuid="f71382dc-97f2-4398-a7fd-cd6155b23f83" split="1"/>
<region uuid="f75990b4-77ef-4d38-950e-631e3b3b8fbb" bg-color="4292728527" position-x="20" position-y="117" size-x="0" size-x2="255" size-y="0" size-y2="484"/>
<entity uuid="fc3df9ba-7e50-4415-90d4-6009251c5942" bg-color="4294967295" hdr-color="4292006610" position-x="209" position-y="47" size-x="0" size-x2="96" size-y="0" size-y2="60"/>
<entity uuid="fc3df9ba-7e50-4415-90d4-6009251c5942" bg-color="4294967295" hdr-color="4292006610" position-x="174" position-y="23" size-x="0" size-x2="96" size-y="0" size-y2="60"/>
</visual-data>
</skipper>
Loading

0 comments on commit 576469c

Please sign in to comment.