Skip to content

Improve setup docs regarding Doctrine ODM #483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 73 additions & 90 deletions Resources/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,28 +284,23 @@ You now can run the following command to create the model:
namespace Acme\ApiBundle\Document;

use FOS\OAuthServerBundle\Document\Client as BaseClient;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/**
* @ODM\Document
*/
class Client extends BaseClient
{

/**
* @ODM\Id
*
* @var string|null
*/
protected $id;
}
```

``` xml
<!-- src/Acme/ApiBundle/Resources/config/doctrine/Client.mongodb.xml -->

<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">

<document name="Acme\ApiBundle\Document\Client" db="acme" collection="oauthClient" customId="true">
<field fieldName="id" id="true" strategy="AUTO" />
</document>

</doctrine-mongo-mapping>
```

``` php
<?php

Expand All @@ -315,40 +310,36 @@ namespace Acme\ApiBundle\Document;

use FOS\OAuthServerBundle\Document\AuthCode as BaseAuthCode;
use FOS\OAuthServerBundle\Model\ClientInterface;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/**
* @ODM\Document
*/
class AuthCode extends BaseAuthCode
{
/**
* @ODM\Id
*
* @var string|null
*/
protected $id;
protected $client;

public function getClient()
{
return $this->client;
}
/**
* @var ClientInterface|null
*
* @ODM\ReferenceOne(targetDocument=Client::class)
*/
protected $client;

public function setClient(ClientInterface $client)
{
$this->client = $client;
}
/**
* @var Your\Own\Entity\User|null
*
* @ODM\ReferenceOne(targetDocument=Your\Own\Entity\User::class)
*/
protected $user;
}
```

``` xml
<!-- src/Acme/ApiBundle/Resources/config/doctrine/AuthCode.mongodb.xml -->

<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">

<document name="Acme\ApiBundle\Document\AuthCode" db="acme" collection="oauthAuthCode" customId="true">
<field fieldName="id" id="true" strategy="AUTO" />
<reference-one target-document="Acme\ApiBundle\Document\Client" field="client" />
</document>

</doctrine-mongo-mapping>
```

``` php
<?php

Expand All @@ -358,40 +349,36 @@ namespace Acme\ApiBundle\Document;

use FOS\OAuthServerBundle\Document\AccessToken as BaseAccessToken;
use FOS\OAuthServerBundle\Model\ClientInterface;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/**
* @ODM\Document
*/
class AccessToken extends BaseAccessToken
{
/**
* @ODM\Id
*
* @var string|null
*/
protected $id;
protected $client;

public function getClient()
{
return $this->client;
}
/**
* @var ClientInterface|null
*
* @ODM\ReferenceOne(targetDocument=Client::class)
*/
protected $client;

public function setClient(ClientInterface $client)
{
$this->client = $client;
}
/**
* @var Your\Own\Entity\User|null
*
* @ODM\ReferenceOne(targetDocument=Your\Own\Entity\User::class)
*/
protected $user;
}
```

``` xml
<!-- src/Acme/ApiBundle/Resources/config/doctrine/AccessToken.mongodb.xml -->

<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">

<document name="Acme\ApiBundle\Document\AccessToken" db="acme" collection="oauthAccessToken" customId="true">
<field fieldName="id" id="true" strategy="AUTO" />
<reference-one target-document="Acme\ApiBundle\Document\Client" field="client" />
</document>

</doctrine-mongo-mapping>
```

``` php
<?php

Expand All @@ -401,40 +388,36 @@ namespace Acme\ApiBundle\Document;

use FOS\OAuthServerBundle\Document\RefreshToken as BaseRefreshToken;
use FOS\OAuthServerBundle\Model\ClientInterface;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/**
* @ODM\Document
*/
class RefreshToken extends BaseRefreshToken
{
/**
* @ODM\Id
*
* @var string|null
*/
protected $id;
protected $client;

public function getClient()
{
return $this->client;
}
/**
* @var ClientInterface|null
*
* @ODM\ReferenceOne(targetDocument=Client::class)
*/
protected $client;

public function setClient(ClientInterface $client)
{
$this->client = $client;
}
/**
* @var Your\Own\Entity\User|null
*
* @ODM\ReferenceOne(targetDocument=Your\Own\Entity\User::class)
*/
protected $user;
}
```

``` xml
<!-- src/Acme/ApiBundle/Resources/config/doctrine/RefreshToken.mongodb.xml -->

<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">

<document name="Acme\ApiBundle\Document\RefreshToken" db="acme" collection="oauthRefreshToken" customId="true">
<field fieldName="id" id="true" strategy="AUTO" />
<reference-one target-document="Acme\ApiBundle\Document\Client" field="client" />
</document>

</doctrine-mongo-mapping>
```

### Step 4: Configure your application's security.yml

In order for Symfony's security component to use the FOSOAuthServerBundle, you must
Expand Down