Skip to content

Api #146

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Api #146

Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public function registerBundles()
new AntiMattr\GoogleBundle\GoogleBundle(),
new Aga\DateConverterBundle\DateConverterBundle(),
new Eko\FeedBundle\EkoFeedBundle(),
new FOS\OAuthServerBundle\FOSOAuthServerBundle(),
new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle($this),
new Cobase\ApiBundle\CobaseApiBundle(),
);

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
Expand Down
43 changes: 43 additions & 0 deletions app/DoctrineMigrations/Version20130805150654.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Application\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration,
Doctrine\DBAL\Schema\Schema;

/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20130805150654 extends AbstractMigration
{
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'.");

$this->addSql("CREATE TABLE AccessToken (id INT AUTO_INCREMENT NOT NULL, client_id INT NOT NULL, user_id INT DEFAULT NULL, token VARCHAR(255) NOT NULL, expires_at INT DEFAULT NULL, scope VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_B39617F55F37A13B (token), INDEX IDX_B39617F519EB6921 (client_id), INDEX IDX_B39617F5A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("CREATE TABLE Client (id INT AUTO_INCREMENT NOT NULL, random_id VARCHAR(255) NOT NULL, redirect_uris LONGTEXT NOT NULL COMMENT '(DC2Type:array)', secret VARCHAR(255) NOT NULL, allowed_grant_types LONGTEXT NOT NULL COMMENT '(DC2Type:array)', name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("CREATE TABLE RefreshToken (id INT AUTO_INCREMENT NOT NULL, client_id INT NOT NULL, user_id INT DEFAULT NULL, token VARCHAR(255) NOT NULL, expires_at INT DEFAULT NULL, scope VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_7142379E5F37A13B (token), INDEX IDX_7142379E19EB6921 (client_id), INDEX IDX_7142379EA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("CREATE TABLE AuthCode (id INT AUTO_INCREMENT NOT NULL, client_id INT NOT NULL, user_id INT DEFAULT NULL, token VARCHAR(255) NOT NULL, redirect_uri LONGTEXT NOT NULL, expires_at INT DEFAULT NULL, scope VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_F1D7D1775F37A13B (token), INDEX IDX_F1D7D17719EB6921 (client_id), INDEX IDX_F1D7D177A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
$this->addSql("ALTER TABLE AccessToken ADD CONSTRAINT FK_B39617F519EB6921 FOREIGN KEY (client_id) REFERENCES Client (id)");
$this->addSql("ALTER TABLE AccessToken ADD CONSTRAINT FK_B39617F5A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)");
$this->addSql("ALTER TABLE RefreshToken ADD CONSTRAINT FK_7142379E19EB6921 FOREIGN KEY (client_id) REFERENCES Client (id)");
$this->addSql("ALTER TABLE RefreshToken ADD CONSTRAINT FK_7142379EA76ED395 FOREIGN KEY (user_id) REFERENCES user (id)");
$this->addSql("ALTER TABLE AuthCode ADD CONSTRAINT FK_F1D7D17719EB6921 FOREIGN KEY (client_id) REFERENCES Client (id)");
$this->addSql("ALTER TABLE AuthCode ADD CONSTRAINT FK_F1D7D177A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)");
}

public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'.");

$this->addSql("ALTER TABLE AccessToken DROP FOREIGN KEY FK_B39617F519EB6921");
$this->addSql("ALTER TABLE RefreshToken DROP FOREIGN KEY FK_7142379E19EB6921");
$this->addSql("ALTER TABLE AuthCode DROP FOREIGN KEY FK_F1D7D17719EB6921");
$this->addSql("DROP TABLE AccessToken");
$this->addSql("DROP TABLE Client");
$this->addSql("DROP TABLE RefreshToken");
$this->addSql("DROP TABLE AuthCode");
}
}
20 changes: 20 additions & 0 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,23 @@ eko_feed:
description: 'Latest posts'
link: 'cobase.featurice.com'
encoding: 'utf-8'

fos_oauth_server:
db_driver: orm # Driver availables: orm, mongodb, or propel
client_class: Cobase\ApiBundle\Entity\Client
access_token_class: Cobase\ApiBundle\Entity\AccessToken
refresh_token_class: Cobase\ApiBundle\Entity\RefreshToken
auth_code_class: Cobase\ApiBundle\Entity\AuthCode
service:
user_provider: fos_user.user_manager

sensio_framework_extra:
view:
annotations: false

fos_rest:
param_fetcher_listener: true
body_listener: true
format_listener: true
view:
view_response_listener: 'force'
18 changes: 14 additions & 4 deletions app/config/routing.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Internal routing configuration to handle ESI
#_internal:
# resource: "@FrameworkBundle/Resources/config/routing/internal.xml"
# prefix: /_internal
fos_oauth_server_token:
resource: "@FOSOAuthServerBundle/Resources/config/routing/token.xml"

fos_oauth_server_authorize:
resource: "@FOSOAuthServerBundle/Resources/config/routing/authorize.xml"

CobaseApiBundle:
resource: "@CobaseApiBundle/Resources/config/routing.yml"
prefix: /api/v1

CobaseAppBundle:
resource: "@CobaseAppBundle/Resources/config/routing.yml"
Expand All @@ -12,3 +17,8 @@ _user_bundle:

fos_js_routing:
resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"

# Internal routing configuration to handle ESI
#_internal:
# resource: "@FrameworkBundle/Resources/config/routing/internal.xml"
# prefix: /_internal
33 changes: 28 additions & 5 deletions app/config/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ security:
FOS\UserBundle\Model\UserInterface: sha512

firewalls:
oauth_authorize:
pattern: ^/api/oauth/v2/auth
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
check_path: /api/oauth/v2/auth_login_check
login_path: /api/oauth/v2/auth_login
logout: true
anonymous: true

oauth_token:
pattern: ^/api/oauth/v2/token
security: false

api:
pattern: ^/api
fos_oauth: true
stateless: true

main:
pattern: ^/
form_login:
Expand All @@ -26,22 +45,26 @@ security:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting$, role: IS_AUTHENTICATED_ANONYMOUSLY }

- { path: ^/profile, role: ROLE_USER }

- { path: ^/post/new, role: ROLE_USER }
- { path: ^/post/create, role: ROLE_USER }
- { path: ^/post/move, role: ROLE_USER }
- { path: ^/post/modify, role: ROLE_USER }
- { path: ^/post/delete, role: ROLE_USER }

- { path: ^/group/new, role: ROLE_USER }
- { path: ^/group/create, role: ROLE_USER }
- { path: ^/group/modify, role: ROLE_USER }
- { path: ^/group/delete, role: ROLE_USER }
- { path: ^/group/subscribe, role: ROLE_USER }
- { path: ^/group/unsubscribe, role: ROLE_USER }


# for the api
- { path: ^/api/oauth/v2/auth_login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api, role: IS_AUTHENTICATED_FULLY }

role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
ROLE_SUPER_ADMIN: ROLE_ADMIN
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
"antimattr/google-bundle": "dev-master",
"artur-gajewski/date-converter-bundle": "1.0.*@dev",
"gedmo/doctrine-extensions": "dev-wip-v2.4.0",
"eko/feedbundle": "dev-master"
"eko/feedbundle": "dev-master",
"friendsofsymfony/oauth-server-bundle": "dev-master",
"friendsofsymfony/rest-bundle": "dev-master",
"jms/serializer-bundle": "dev-master"
},
"scripts": {
"post-install-cmd": [
Expand Down
Loading