Skip to content

Commit

Permalink
Fix for #3: Made oauth server compatible with PostgreSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
rhertogh committed Sep 8, 2022
1 parent a1fd399 commit dbb3a5b
Showing 39 changed files with 1,780 additions and 309 deletions.
7 changes: 7 additions & 0 deletions docker/Yii2Oauth2Server/Dockerfile
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@ FROM yiisoftware/yii2-php:7.4-apache
ARG APP_DIR=/app
RUN echo "APP_DIR: ${APP_DIR}"

RUN echo "deb http://ftp.de.debian.org/debian buster main" >> /etc/apt/sources.list

RUN apt-get update

#region Not required but often used for debugging
@@ -14,6 +16,11 @@ COPY docker/Yii2Oauth2Server/apache/vhost.conf /etc/apache2/sites-available/000-
# Create alias for PHP with Xdebug
RUN echo 'alias phpx="php -d xdebug.start_with_request=1"' >> ~/.bashrc

# Enable pdo_postgres
RUN apt-get install -y libpq-dev
RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql
RUN docker-php-ext-install pdo pdo_pgsql pgsql

# Copy the app directory. NOTE! For development docker-compose will overwrite this directory with a mount
COPY . ${APP_DIR}

1 change: 1 addition & 0 deletions src/components/repositories/Oauth2ScopeRepository.php
Original file line number Diff line number Diff line change
@@ -83,6 +83,7 @@ public function finalizeScopes(
'user_client_scope.client_id' => $client->getPrimaryKey(),
'user_client_scope.enabled' => 1,
])
->orderBy('id')
->indexBy('id')
->all();

614 changes: 463 additions & 151 deletions src/migrations/Oauth2_00001_CreateOauth2TablesMigration.php

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/migrations/base/Oauth2BaseMigration.php
Original file line number Diff line number Diff line change
@@ -10,6 +10,9 @@

abstract class Oauth2BaseMigration extends Migration
{
public const RESTRICT = 'RESTRICT';
public const CASCADE = 'CASCADE';

/**
* Determines if the migration should be generated for the current module configuration.
* @param Oauth2Module $module
1 change: 1 addition & 0 deletions src/models/Oauth2Client.php
Original file line number Diff line number Diff line change
@@ -563,6 +563,7 @@ public function getAllowedScopes($requestedScopeIdentifiers = [])
->joinWith('clientScopes', true)
->enabled()
->andWhere(['OR', ...$possibleScopesConditions])
->orderBy('id')
->all();
}
}
25 changes: 16 additions & 9 deletions src/models/base/Oauth2AccessToken.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This class was automatically generated by a giiant build task.
// You should not change it manually as it will be overwritten on next build.

@@ -10,7 +9,7 @@
/**
* This is the base-model class for table "oauth2_access_token".
*
* @property string $id
* @property integer $id
* @property string $identifier
* @property integer $client_id
* @property integer $user_id
@@ -20,7 +19,7 @@
* @property integer $allowance
* @property integer $allowance_updated_at
* @property string $expiry_date_time
* @property integer $enabled
* @property boolean $enabled
* @property integer $created_at
* @property integer $updated_at
*
@@ -34,15 +33,21 @@
*/
abstract class Oauth2AccessToken extends \rhertogh\Yii2Oauth2Server\models\base\Oauth2BaseActiveRecord
{




/**
* @inheritdoc
*/
public function rules()
{
return [
[['identifier', 'client_id', 'type', 'expiry_date_time', 'created_at', 'updated_at'], 'required'],
[['client_id', 'user_id', 'type', 'mac_algorithm', 'allowance', 'allowance_updated_at', 'enabled', 'created_at', 'updated_at'], 'integer'],
[['client_id', 'user_id', 'type', 'mac_algorithm', 'allowance', 'allowance_updated_at', 'created_at', 'updated_at'], 'default', 'value' => null],
[['client_id', 'user_id', 'type', 'mac_algorithm', 'allowance', 'allowance_updated_at', 'created_at', 'updated_at'], 'integer'],
[['expiry_date_time'], 'safe'],
[['enabled'], 'boolean'],
[['identifier'], 'string', 'max' => 255],
[['mac_key'], 'string', 'max' => 500],
[['identifier'], 'unique']
@@ -70,28 +75,28 @@ public function attributeLabels()
'updated_at' => Yii::t('oauth2', 'Updated At'),
];
}

/**
* @return \rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2AccessTokenScopeQueryInterface */
public function getAccessTokenScopes()
{
return $this->hasMany(\rhertogh\Yii2Oauth2Server\models\Oauth2AccessTokenScope::className(), ['access_token_id' => 'id'])->inverseOf('accessToken');
}

/**
* @return \rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2ClientQueryInterface */
public function getClient()
{
return $this->hasOne(\rhertogh\Yii2Oauth2Server\models\Oauth2Client::className(), ['id' => 'client_id'])->inverseOf('accessTokens');
}

/**
* @return \rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2RefreshTokenQueryInterface */
public function getRefreshTokens()
{
return $this->hasMany(\rhertogh\Yii2Oauth2Server\models\Oauth2RefreshToken::className(), ['access_token_id' => 'id'])->inverseOf('accessToken');
}

/**
* @return \rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2ScopeQueryInterface */
public function getScopes()
@@ -100,7 +105,7 @@ public function getScopes()
}



/**
* @inheritdoc
* @return \rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2AccessTokenQueryInterface the active query used by this AR class.
@@ -109,4 +114,6 @@ public static function find()
{
return Yii::createObject(\rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2AccessTokenQueryInterface::class, [get_called_class()]);
}


}
16 changes: 11 additions & 5 deletions src/models/base/Oauth2AccessTokenScope.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This class was automatically generated by a giiant build task.
// You should not change it manually as it will be overwritten on next build.

@@ -10,7 +9,7 @@
/**
* This is the base-model class for table "oauth2_access_token_scope".
*
* @property string $access_token_id
* @property integer $access_token_id
* @property integer $scope_id
* @property integer $created_at
*
@@ -22,13 +21,18 @@
*/
abstract class Oauth2AccessTokenScope extends \rhertogh\Yii2Oauth2Server\models\base\Oauth2BaseActiveRecord
{




/**
* @inheritdoc
*/
public function rules()
{
return [
[['access_token_id', 'scope_id', 'created_at'], 'required'],
[['access_token_id', 'scope_id', 'created_at'], 'default', 'value' => null],
[['access_token_id', 'scope_id', 'created_at'], 'integer'],
[['access_token_id', 'scope_id'], 'unique', 'targetAttribute' => ['access_token_id', 'scope_id']]
];
@@ -45,14 +49,14 @@ public function attributeLabels()
'created_at' => Yii::t('oauth2', 'Created At'),
];
}

/**
* @return \rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2AccessTokenQueryInterface */
public function getAccessToken()
{
return $this->hasOne(\rhertogh\Yii2Oauth2Server\models\Oauth2AccessToken::className(), ['id' => 'access_token_id'])->inverseOf('accessTokenScopes');
}

/**
* @return \rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2ScopeQueryInterface */
public function getScope()
@@ -61,7 +65,7 @@ public function getScope()
}



/**
* @inheritdoc
* @return \rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2AccessTokenScopeQueryInterface the active query used by this AR class.
@@ -70,4 +74,6 @@ public static function find()
{
return Yii::createObject(\rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2AccessTokenScopeQueryInterface::class, [get_called_class()]);
}


}
23 changes: 15 additions & 8 deletions src/models/base/Oauth2AuthCode.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This class was automatically generated by a giiant build task.
// You should not change it manually as it will be overwritten on next build.

@@ -10,13 +9,13 @@
/**
* This is the base-model class for table "oauth2_auth_code".
*
* @property string $id
* @property integer $id
* @property string $identifier
* @property string $redirect_uri
* @property string $expiry_date_time
* @property integer $client_id
* @property integer $user_id
* @property integer $enabled
* @property boolean $enabled
* @property integer $created_at
* @property integer $updated_at
*
@@ -29,6 +28,10 @@
*/
abstract class Oauth2AuthCode extends \rhertogh\Yii2Oauth2Server\models\base\Oauth2BaseActiveRecord
{




/**
* @inheritdoc
*/
@@ -37,7 +40,9 @@ public function rules()
return [
[['identifier', 'expiry_date_time', 'client_id', 'user_id', 'created_at', 'updated_at'], 'required'],
[['expiry_date_time'], 'safe'],
[['client_id', 'user_id', 'enabled', 'created_at', 'updated_at'], 'integer'],
[['client_id', 'user_id', 'created_at', 'updated_at'], 'default', 'value' => null],
[['client_id', 'user_id', 'created_at', 'updated_at'], 'integer'],
[['enabled'], 'boolean'],
[['identifier', 'redirect_uri'], 'string', 'max' => 255],
[['identifier'], 'unique']
];
@@ -60,21 +65,21 @@ public function attributeLabels()
'updated_at' => Yii::t('oauth2', 'Updated At'),
];
}

/**
* @return \rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2AuthCodeScopeQueryInterface */
public function getAuthCodeScopes()
{
return $this->hasMany(\rhertogh\Yii2Oauth2Server\models\Oauth2AuthCodeScope::className(), ['auth_code_id' => 'id'])->inverseOf('authCode');
}

/**
* @return \rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2ClientQueryInterface */
public function getClient()
{
return $this->hasOne(\rhertogh\Yii2Oauth2Server\models\Oauth2Client::className(), ['id' => 'client_id'])->inverseOf('authCodes');
}

/**
* @return \rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2ScopeQueryInterface */
public function getScopes()
@@ -83,7 +88,7 @@ public function getScopes()
}



/**
* @inheritdoc
* @return \rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2AuthCodeQueryInterface the active query used by this AR class.
@@ -92,4 +97,6 @@ public static function find()
{
return Yii::createObject(\rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2AuthCodeQueryInterface::class, [get_called_class()]);
}


}
16 changes: 11 additions & 5 deletions src/models/base/Oauth2AuthCodeScope.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This class was automatically generated by a giiant build task.
// You should not change it manually as it will be overwritten on next build.

@@ -10,7 +9,7 @@
/**
* This is the base-model class for table "oauth2_auth_code_scope".
*
* @property string $auth_code_id
* @property integer $auth_code_id
* @property integer $scope_id
* @property integer $created_at
*
@@ -22,13 +21,18 @@
*/
abstract class Oauth2AuthCodeScope extends \rhertogh\Yii2Oauth2Server\models\base\Oauth2BaseActiveRecord
{




/**
* @inheritdoc
*/
public function rules()
{
return [
[['auth_code_id', 'scope_id', 'created_at'], 'required'],
[['auth_code_id', 'scope_id', 'created_at'], 'default', 'value' => null],
[['auth_code_id', 'scope_id', 'created_at'], 'integer'],
[['auth_code_id', 'scope_id'], 'unique', 'targetAttribute' => ['auth_code_id', 'scope_id']]
];
@@ -45,14 +49,14 @@ public function attributeLabels()
'created_at' => Yii::t('oauth2', 'Created At'),
];
}

/**
* @return \rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2AuthCodeQueryInterface */
public function getAuthCode()
{
return $this->hasOne(\rhertogh\Yii2Oauth2Server\models\Oauth2AuthCode::className(), ['id' => 'auth_code_id'])->inverseOf('authCodeScopes');
}

/**
* @return \rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2ScopeQueryInterface */
public function getScope()
@@ -61,7 +65,7 @@ public function getScope()
}



/**
* @inheritdoc
* @return \rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2AuthCodeScopeQueryInterface the active query used by this AR class.
@@ -70,4 +74,6 @@ public static function find()
{
return Yii::createObject(\rhertogh\Yii2Oauth2Server\interfaces\models\queries\Oauth2AuthCodeScopeQueryInterface::class, [get_called_class()]);
}


}
Loading

0 comments on commit dbb3a5b

Please sign in to comment.