Skip to content

Commit

Permalink
wip oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasLudvik authored and Svaťa Šimara committed May 27, 2019
1 parent 1d04bde commit 0baf7b3
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 1 deletion.
4 changes: 3 additions & 1 deletion composer.json
Expand Up @@ -144,7 +144,9 @@
"twig/extensions": "^1.5.1",
"twig/twig": "^2.4.8",
"vasek-purchart/console-errors-bundle": "^1.0.1",
"webmozart/assert": "^1.4"
"webmozart/assert": "^1.4",
"trikoder/oauth2-bundle": "^1.1",
"nyholm/psr7": "^1.1"
},
"require-dev": {
"ext-pgsql": "*",
Expand Down
34 changes: 34 additions & 0 deletions packages/api/src/Migrations/Version20190524102901.php
@@ -0,0 +1,34 @@
<?php

namespace Shopsys\ApiBundle\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Shopsys\MigrationBundle\Component\Doctrine\Migrations\AbstractMigration;

class Version20190524102901 extends AbstractMigration
{
/**
* @param \Doctrine\DBAL\Schema\Schema $schema
*/
public function up(Schema $schema)
{
$this->sql('CREATE TABLE oauth2_access_token (identifier CHAR(80) NOT NULL, client VARCHAR(32) NOT NULL, expiry TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, user_identifier VARCHAR(128) DEFAULT NULL, scopes TEXT DEFAULT NULL, revoked BOOLEAN NOT NULL, PRIMARY KEY(identifier));');
$this->sql('CREATE INDEX IDX_454D9673C7440455 ON oauth2_access_token (client);');
$this->sql('COMMENT ON COLUMN oauth2_access_token.scopes IS \'(DC2Type:oauth2_scope)\';');
$this->sql('CREATE TABLE oauth2_client (identifier VARCHAR(32) NOT NULL, secret VARCHAR(128) NOT NULL, redirect_uris TEXT DEFAULT NULL, grants TEXT DEFAULT NULL, scopes TEXT DEFAULT NULL, active BOOLEAN NOT NULL, PRIMARY KEY(identifier));');
$this->sql('COMMENT ON COLUMN oauth2_client.redirect_uris IS \'(DC2Type:oauth2_redirect_uri)\';');
$this->sql('COMMENT ON COLUMN oauth2_client.grants IS \'(DC2Type:oauth2_grant)\';');
$this->sql('COMMENT ON COLUMN oauth2_client.scopes IS \'(DC2Type:oauth2_scope)\';');
$this->sql('CREATE TABLE oauth2_refresh_token (identifier CHAR(80) NOT NULL, access_token CHAR(80) NOT NULL, expiry TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, revoked BOOLEAN NOT NULL, PRIMARY KEY(identifier));');
$this->sql('CREATE INDEX IDX_4DD90732B6A2DD68 ON oauth2_refresh_token (access_token);');
$this->sql('ALTER TABLE oauth2_access_token ADD CONSTRAINT FK_454D9673C7440455 FOREIGN KEY (client) REFERENCES oauth2_client (identifier) NOT DEFERRABLE INITIALLY IMMEDIATE;');
$this->sql('ALTER TABLE oauth2_refresh_token ADD CONSTRAINT FK_4DD90732B6A2DD68 FOREIGN KEY (access_token) REFERENCES oauth2_access_token (identifier) NOT DEFERRABLE INITIALLY IMMEDIATE;');
}

/**
* @param \Doctrine\DBAL\Schema\Schema $schema
*/
public function down(Schema $schema)
{
}
}
3 changes: 3 additions & 0 deletions packages/api/src/Resources/config/routing.yml
Expand Up @@ -2,3 +2,6 @@ shopsys_api:
resource: "@ShopsysApiBundle/Controller/V1"
prefix: /api/v1
type: annotation

oauth2:
resource: '@TrikoderOAuth2Bundle/Resources/config/routes.xml'
1 change: 1 addition & 0 deletions project-base/app/AppKernel.php
Expand Up @@ -51,6 +51,7 @@ public function registerBundles()
new Shopsys\ReadModelBundle\ShopsysReadModelBundle(), // has to be loaded after ShopsysFrameworkBundle because it overrides Twig `image` function
new Shopsys\ShopBundle\ShopsysShopBundle(), // must be loaded as last, because translations must overwrite other bundles
new FOS\RestBundle\FOSRestBundle(),
new Trikoder\Bundle\OAuth2Bundle\TrikoderOAuth2Bundle(),
];

if ($this->getEnvironment() === EnvironmentType::DEVELOPMENT) {
Expand Down
8 changes: 8 additions & 0 deletions project-base/app/config/packages/security.yml
Expand Up @@ -64,6 +64,14 @@ security:
csrf_token_generator: security.csrf.token_manager
csrf_token_id: frontend_logout
invalidate_session: false
api_token:
pattern: ^/api/token$
security: false
api:
pattern: ^/api
security: true
stateless: true
oauth2: true

access_control:
# same pattern must be in routing_front.yml
Expand Down
33 changes: 33 additions & 0 deletions project-base/app/config/packages/trikoder_oauth2.yml
@@ -0,0 +1,33 @@
trikoder_oauth2:
authorization_server:
# Full path to the private key file.
# How to generate a private key: https://oauth2.thephpleague.com/installation/#generating-public-and-private-keys
private_key: '%shopsys.root_dir%/app/config/private.key'

# The string used as an encryption key.
# How to generate an encryption key: https://oauth2.thephpleague.com/installation/#string-password
encryption_key: iRuA3af4/Fva1lujo+7y3f9LUI8a7n1TVNw8WZvF1Tw=

# How long the issued access token should be valid for.
# The value should be a valid interval: http://php.net/manual/en/dateinterval.construct.php#refsect1-dateinterval.construct-parameters
access_token_ttl: PT1H

# How long the issued refresh token should be valid for.
# The value should be a valid interval: http://php.net/manual/en/dateinterval.construct.php#refsect1-dateinterval.construct-parameters
refresh_token_ttl: P1M

resource_server:
# Full path to the public key file
# How to generate a public key: https://oauth2.thephpleague.com/installation/#generating-public-and-private-keys
public_key: '%shopsys.root_dir%/app/config/public.key'

# Scopes that you wish to utilize in your application.
# This should be a simple array of strings.
scopes: []

# Configures different persistence methods that can be used by the bundle for saving client and token data.
# Only one persistence method can be configured at a time.
persistence:
doctrine:
# Name of the entity manager that you wish to use for managing clients and tokens.
entity_manager: default # Required
27 changes: 27 additions & 0 deletions project-base/app/config/private.key
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEA4Y3boig3D3Si/OxTJfGz2bm68lTydupL0f5vFU1pPfQ73eKR
p7oFH2i5TNKtUY5Ys48Sr/iyv4s10YhjhouJmt/3OvaFD09yo07Vi7osoPqFZWIc
84Z0lNmZxRjNhD5K3eIqKGBE9894mpSG4OoiWv610RvVdHOLNLq/tQtBWHwILPS/
vkSn5pZxcBaLX285s5qGXskBLrbuU9oqZvfIArXxNhrVuGlhmMFKJ0cFOJ45OT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vntKKFBHyz1PUA5Fvton1k9CpxF2sS
TkqkWOnlKw3H0WUxspZmLB0A4XdUwM1d+hHN5P80oWZvTRRk4y65J0BzIEcQiFHL
Jb5gIZECgYEAtNeBia3WRDx5oWkgrQV30ykuOT5XMCaCSxzQkTCILCZ2mNbZ4pS1
Lhx7/h1v3IC+xbSTIEtWwtoZB8K3HcUGqA/eMLx5kwp9TnM5W2AzTO6AouxiQD0E
GzN9fI2yAxeS8A1DrRX/U/89p/swBT3E+GJ0/3KfTu9onaT/um1XpsY=
-----END RSA PRIVATE KEY-----
9 changes: 9 additions & 0 deletions project-base/app/config/public.key
@@ -0,0 +1,9 @@
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4Y3boig3D3Si/OxTJfGz
2bm68lTydupL0f5vFU1pPfQ73eKRp7oFH2i5TNKtUY5Ys48Sr/iyv4s10YhjhouJ
mt/3OvaFD09yo07Vi7osoPqFZWIc84Z0lNmZxRjNhD5K3eIqKGBE9894mpSG4Ooi
Wv610RvVdHOLNLq/tQtBWHwILPS/vkSn5pZxcBaLX285s5qGXskBLrbuU9oqZvfI
ArXxNhrVuGlhmMFKJ0cFOJ45OTtpogBQYaLt0m8AN4RDE9Qy11t88mR2pLfHJlyx
3gw2kh5itL9GkKsnfNS+zxh+2XqOG9oLsvtNskQEyjEaBXUX3r7B1lulHTibvnyl
1QIDAQAB
-----END PUBLIC KEY-----

0 comments on commit 0baf7b3

Please sign in to comment.