Skip to content

Commit

Permalink
Merge pull request #30 from bshaffer/develop
Browse files Browse the repository at this point in the history
v0.3
  • Loading branch information
bshaffer committed Oct 15, 2014
2 parents 0db61b8 + e304ee7 commit 6cf4717
Show file tree
Hide file tree
Showing 30 changed files with 515 additions and 126 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ php:
- 5.4
- 5.5
env:
- CONTAINER_CONFIG=Resources/config/services_test.xml
- CONTAINER_CONFIG=Tests/Resources/config/services.xml
before_script:
- composer install
- cp phpunit.xml.dist phpunit.xml
Expand Down
43 changes: 0 additions & 43 deletions Controller/ResourceController.php

This file was deleted.

7 changes: 7 additions & 0 deletions Entity/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ public function getUserId()
*/
public function setExpires($expires)
{
if (!$expires instanceof \DateTime) {
// @see https://github.com/bshaffer/oauth2-server-bundle/issues/24
$dateTime = new \DateTime();
$dateTime->setTimestamp($expires);
$expires = $dateTime;
}

$this->expires = $expires;

return $this;
Expand Down
7 changes: 7 additions & 0 deletions Entity/AuthorizationCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ public function getCode()
*/
public function setExpires($expires)
{
if (!$expires instanceof \DateTime) {
// @see https://github.com/bshaffer/oauth2-server-bundle/issues/24
$dateTime = new \DateTime();
$dateTime->setTimestamp($expires);
$expires = $dateTime;
}

$this->expires = $expires;

return $this;
Expand Down
30 changes: 29 additions & 1 deletion Entity/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ class Client
private $redirect_uri;

/**
* @var array
* @var \OAuth2\ServerBundle\Entity\ClientPublicKey $public_key
*/
private $grant_types;

/**
* @var string
*/
private $public_key;

/**
* Set client_id
*
Expand Down Expand Up @@ -145,4 +150,27 @@ public function getScopes()
{
return $this->scopes;
}

/**
* Set public key
*
* @param \OAuth2\ServerBundle\Entity\ClientPublicKey $public_key
* @return Client
*/
public function setPublicKey(\OAuth2\ServerBundle\Entity\ClientPublicKey $public_key = null)
{
$this->public_key = $public_key;

return $this;
}

/**
* Get public key
*
* @return \OAuth2\ServerBundle\Entity\ClientPublicKey
*/
public function getPublicKey()
{
return $this->public_key;
}
}
73 changes: 73 additions & 0 deletions Entity/ClientPublicKey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace OAuth2\ServerBundle\Entity;

/**
* Client
*/
class ClientPublicKey
{
/**
* @var \OAuth2\ServerBundle\Entity\Client
*/
private $client;

/**
* @var integer
*/
private $client_id;

/**
* @var string
*/
private $public_key;

/**
* Set client
*
* @param \OAuth2\ServerBundle\Entity\Client $client
* @return ClientPublicKey
*/
public function setClient(\OAuth2\ServerBundle\Entity\Client $client = null)
{
$this->client = $client;

// this is necessary as the client_id is the primary key
$this->client_id = $client->getClientId();

return $this;
}

/**
* Get client
*
* @return \OAuth2\ServerBundle\Entity\Client
*/
public function getClient()
{
return $this->client;
}

/**
* Set public key
*
* @param string $public_key
* @return Client
*/
public function setPublicKey($public_key)
{
$this->public_key = $public_key;

return $this;
}

/**
* Get public key
*
* @return string
*/
public function getPublicKey()
{
return $this->public_key;
}
}
7 changes: 7 additions & 0 deletions Entity/RefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ public function getUserId()
*/
public function setExpires($expires)
{
if (!$expires instanceof \DateTime) {
// @see https://github.com/bshaffer/oauth2-server-bundle/issues/24
$dateTime = new \DateTime();
$dateTime->setTimestamp($expires);
$expires = $dateTime;
}

$this->expires = $expires;

return $this;
Expand Down
10 changes: 8 additions & 2 deletions Manager/ClientManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ class ClientManager
{
private $em;

public function __construct(EntityManager $entityManager)
/**
* @var ScopeManagerInterface
*/
private $sm;

public function __construct(EntityManager $entityManager, ScopeManagerInterface $scopeManager)
{
$this->em = $entityManager;
$this->sm = $scopeManager;
}

/**
Expand All @@ -38,7 +44,7 @@ public function createClient($identifier, array $redirect_uris = array(), array
// Verify scopes
foreach ($scopes as $scope) {
// Get Scope
$scopeObject = $this->em->getRepository('OAuth2ServerBundle:Scope')->find($scope);
$scopeObject = $this->sm->findScopeByScope($scope);
if (!$scopeObject) {
throw new ScopeNotFoundException();
}
Expand Down
32 changes: 31 additions & 1 deletion Manager/ScopeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Doctrine\ORM\EntityManager;

class ScopeManager
class ScopeManager implements ScopeManagerInterface
{
private $em;

Expand Down Expand Up @@ -34,4 +34,34 @@ public function createScope($scope, $description = null)

return $scopeObject;
}

/**
* Find a single scope by the scope
*
* @param $scope
* @return Scope
*/
public function findScopeByScope($scope)
{
$scopeObject = $this->em->getRepository('OAuth2ServerBundle:Scope')->find($scope);

return $scopeObject;
}

/**
* Find all the scopes by an array of scopes
*
* @param array $scopes
* @return mixed|void
*/
public function findScopesByScopes(array $scopes)
{
$scopeObjects = $this->em->getRepository('OAuth2ServerBundle:Scope')
->createQueryBuilder('a')
->where('a.scope in (?1)')
->setParameter(1, implode(',', $scopes))
->getQuery()->getResult();

return $scopeObjects;
}
}
37 changes: 37 additions & 0 deletions Manager/ScopeManagerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace OAuth2\ServerBundle\Manager;

use Doctrine\ORM\EntityManager;

interface ScopeManagerInterface
{
public function __construct(EntityManager $entityManager);

/**
* Creates a new scope
*
* @param string $scope
*
* @param string $description
*
* @return Scope
*/
public function createScope($scope, $description = null);

/**
* Find a single scope by the scope
*
* @param $scope
* @return Scope
*/
public function findScopeByScope($scope);

/**
* Find all the scopes by an array of scopes
*
* @param array $scopes
* @return mixed
*/
public function findScopesByScopes(array $scopes);
}
30 changes: 13 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# OAuth2 Server Bundle

OAuth2 Server Bundle for Symfony 2.
OAuth2 Server Bundle for Symfony 2, built on the [oauth2-server-php](https://github.com/bshaffer/oauth2-server-php) library.

[![Build Status](https://secure.travis-ci.org/bshaffer/oauth2-server-php.png)](http://travis-ci.org/bshaffer/oauth2-server-php)
[![Build Status](https://secure.travis-ci.org/bshaffer/oauth2-server-bundle.png)](http://travis-ci.org/bshaffer/oauth2-server-bundle)

## Overview
## Getting Started

See the [Complete Documentation](http://bshaffer.github.io/oauth2-server-php-docs/) for information regarding the OAuth2.0 protocol and the PHP library used by this bundle to implement it.

For documentation specific to this bundle, continue reading below.

## Bundle Overview

The following grant types are supported out the box:

Expand Down Expand Up @@ -33,23 +39,13 @@ public function tokenAction()

### Step 1: Add package to Composer

Add the bundle to your composer.json:

``` js
{
"require": {
"bshaffer/oauth2-server-bundle": "dev-master"
}
}
```

Now tell composer to download the bundle by running the command:
Use composer to add the requirement and download it by running the command:

``` bash
$ php composer.phar update bshaffer/oauth2-server-bundle
$ php composer.phar require bshaffer/oauth2-server-bundle
```

Composer will install the bundle to your project's `vendor/bshaffer` directory.
Composer will update your composer.json and install the bundle to your project's `vendor/bshaffer` directory.

### Step 2: Enable the bundle

Expand Down Expand Up @@ -206,4 +202,4 @@ class OAuth2CompilerPass implements CompilerPassInterface
}
}
```
```
19 changes: 19 additions & 0 deletions Resources/config/doctrine/ClientPublicKey.orm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
OAuth2\ServerBundle\Entity\ClientPublicKey:
type: entity
table: oauth_client_public_key
id:
client_id:
type: string
length: 50
fields:
public_key:
type: text
oneToOne:
client:
targetEntity: OAuth2\ServerBundle\Entity\Client
joinColumn:
name: client_id
referencedColumnName: client_id
onDelete: CASCADE
onUpdate: CASCADE
lifecycleCallbacks: { }
Loading

0 comments on commit 6cf4717

Please sign in to comment.