paneedesign / api-bundle
Api management for Symfony3 projects.
Installs: 3 156
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^5.6|^7.0
- adoy/oauth2: ^1.3
- friendsofsymfony/oauth-server-bundle: ^1.6
- friendsofsymfony/rest-bundle: ^2.3
- jms/serializer-bundle: ^2.0
- nelmio/api-doc-bundle: ^3.1
- symfony/framework-bundle: ^3.2
Requires (Dev)
- incenteev/composer-parameter-handler: ~2.0
- phpspec/phpspec: ^3.2
- phpunit/phpunit: ^5.6
- symfony/security-bundle: ^3.2
README
Api management for Symfony3 projects.
Installation
Step 1: Download the Bundle
Pane&Design repository is private so, add to composer.json
this vcs
"repositories": [ ... { "type" : "vcs", "url" : "git@bitbucket.org:paneedesign/api-bundle.git" } ], ... "require": { ... "paneedesign/api-bundle": "^3.0" }
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require "paneedesign/api-bundle"
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new \FOS\OAuthServerBundle\FOSOAuthServerBundle(), new \FOS\RestBundle\FOSRestBundle(), new \JMS\SerializerBundle\JMSSerializerBundle(), new \PaneeDesign\ApiBundle\PedApiBundle(), ); // ... if (in_array($this->getEnvironment(), ['dev', 'test'], true)) { // ... $bundles[] = new \Nelmio\ApiDocBundle\NelmioApiDocBundle(); } } // ... }
Step 3: Configurations
Add parameters
// app/config/parameters.yml.dist
parameters:
...
api_server_host: 'https://api.paneedesign.com'
api_type: oauth2
api_client_id: ~
api_client_secret: ~
api_user_class: PaneeDesign\UserBundle\Entity\User
Add configuration
// app/config/config.yml imports: - { resource: "@PedApiBundle/Resources/config/config.yml" } ...
// app/config/config_dev.yml imports: - { resource: "@PedApiBundle/Resources/config/custom/nelmio_api_doc.yml" } ...
// app/config/routing.yml ped_api: resource: '@PedApiBundle/Resources/config/routing.yml' prefix: / ...
Implement API
// app/config/custom/api.yml public_v1: type: rest prefix: /v1 resource: "@PedApiBundle/Controller/Api/ApiPublicController.php" name_prefix: api_1_ ...
Generate client
php bin/console fos:oauth-server:create-client --redirect-uri="https://api.paneedesign.com/authorize" --grant-type="https://api.paneedesign.com/oauth/v2/api_key" --grant-type="password" --grant-type="refresh_token"
Upgrade from 2.x to 3.x
- rename getApiKeyAccessToken in getOAuthToken
- change signature of
throwRefreshTokenJsonException
fromprotected function throwRefreshTokenJsonException(JsonException $jsonException, $expiredAt)
toprotected function throwRefreshTokenJsonException(\OAuth2\OAuth2ServerException $oAuthException)
- change signature of
refreshTokenResponse
fromprotected function refreshTokenResponse(User $user, $accessToken)
toprotected function refreshTokenResponse(User $user, array $oAuthToken)
- remove
api_access_token_expire_at
andapi_refresh_token_expire_at
from parameters - add
api_client_id
andapi_client_secret
to parameters