Closed ivantree closed 4 years ago
+1. Would it be?
foreach($this->storageMap as $name=>$class) { $storages[$name] = \Yii::$container->get($class); }
+1
foreach($this->storageMap as $name=>$class) { $storages[$name] = \Yii::$container->get($class); }
This solution worked for me, I believe a fix is needed
Referencing my comment on https://github.com/Filsh/yii2-oauth2-server/issues/39#issuecomment-246840160
I'm using dev-master.
JWT tokens as described in the readme aren't in the 2.0 release. They are in dev-master however.
@hiqsol @Filsh I've bootstrapped oauth2 module, but didn't seem to make a difference. Still throwing "Class user_credentials does not exist"
Also tried with bshaffer/oauth2-server-php at 1.8
'basePath' => dirname(__DIR__),
'bootstrap' => ['log','oauth2'],
'controllerNamespace' => 'restapi\controllers',
'modules' => [
'oauth2' => [
'class' => 'filsh\yii2\oauth2server\Module',
'useJwtToken' => true,
'tokenParamName' => 'accessToken',
'tokenAccessLifetime' => 3600 * 24,
'storageMap' => [
'user_credentials' => 'restapi\modules\v1\models\ApiUser',
'public_key' => 'restapi\storage\PublicKeyStorage',
'access_token' => 'restapi\storage\JwtAccessToken',
],
'grantTypes' => [
'user_credentials' => [
'class' => 'OAuth2\GrantType\UserCredentials',
],
'refresh_token' => [
'class' => 'OAuth2\GrantType\RefreshToken',
'always_issue_new_refresh_token' => true
]
]
]
],
Also tried checking out the last commit to 2.0.1 (#44aa6091ce128c9fd0e81c684044a6b57fbfc8eb)
Did this fix in main.php for user_credentials error
foreach($this->storageMap as $name => $class) { $storages[$name] = \Yii::$container->get($class); }
But get Invalid grant types configuration for refresh_token
because default storage mappings aren't in there. @mtangoo I saw you took that out in earlier commit.
@mtangoo is your jwt working with dev-master? I don't know what the issue is here.
Ok. My bad. So dev-master has some issues.
I checked out the 2.0.1 branch and JWT is stable and working. No more user_credentials error.
Solution if anyone else is looking:
"filsh/yii2-oauth2-server": "2.0.1.x-dev@dev"
Would be desirable if there was a note about this in the 2.0.0 readme that's default when visiting this repo.
Sorry I have been busy. I think the old branches need to be wiped out of existence. 2.0.1.x-dev ought to be dev-master and out of it come some release.
Am not the author of the extension and have no access to repo, so can't do changes.
I think I will re-write the extension IF I happen to get free time.
I was experimenting with something here and its not hard to do that https://github.com/hosannahighertech/upendo
That's good to know that I'm on the right branch now. Should be helpful if anyone else finds this thread in the mean time. Thanks for clearing that up @mtangoo
So I used
"filsh/yii2-oauth2-server": "2.0.1.x-dev@dev"
as outlined by @edeis53 above, but I am still getting the dreaded "Class user_credentials does not exist" error. Did you make any other configuration changes?
Worked for me. "filsh/yii2-oauth2-server": "2.0.1.x-dev@dev",
You might need to check the readme for that branch, I think it may be different from the master as I recall as part of my confusion. Follow that you should be fine. I am using JWT tokens as well.
@rlmckenney did you run composer update? Ca you post composer.json file?
I am not using JWT yet. I wanted to get the base config working. When I ran composer update I got ...
Updating dependencies (including require-dev)
- Installing bshaffer/oauth2-server-php (v1.8.0)
Loading from cache
- Installing filsh/yii2-oauth2-server (v2.0.1.x-dev 44aa609)
Cloning 44aa6091ce128c9fd0e81c684044a6b57fbfc8eb from cache
and the modules section from my config file is ...
'modules' => [
'oauth2' => [
'class' => 'filsh\yii2\oauth2server\Module',
'useJwtToken' => false,
'tokenParamName' => 'accessToken',
'tokenAccessLifetime' => 3600 * 24,
'storageMap' => [
'user_credentials' => 'api\common\models\User',
],
'grantTypes' => [
// 'client_credentials' => [
// 'class' => 'OAuth2\GrantType\ClientCredentials',
// 'allow_public_clients' => false
// ],
'user_credentials' => [
'class' => 'OAuth2\GrantType\UserCredentials',
],
'refresh_token' => [
'class' => 'OAuth2\GrantType\RefreshToken',
'always_issue_new_refresh_token' => true
]
]
],
'v2' => [
'basePath' => '@app/versions/v2',
'class' => 'api\versions\v2\Module'
],
I am rechecking the README but I don't think that I missed anything.
I have tried enabling JWT with
'useJwtToken' => true,
'storageMap' => [
'user_credentials' => 'api\common\models\User',
'public_key' => 'api\storage\PublicKeyStorage',
'access_token' => 'OAuth2\Storage\JwtAccessToken',
],
and I still have the same problem. What am I missing?
After reading the code and some further experimentation, I was able to get things working. Here is what I did ...
"filsh/yii2-oauth2-server": "2.0.1.x-dev@dev"
in my composer.json as discussed above.foreach(array_keys($this->storageMap) as $name) {
$storages[$name] = \Yii::$container->get($name);
}
with
foreach ($this->storageMap as $name => $class) {
$storages[$name] = \Yii::$container->get($class);
}
\OAuth2\Storage\ClientCredentialsInterface
/**
* @inheritdoc
*/
private function getClient($client_id)
{
return \filsh\yii2\oauth2server\models\OauthClients::findOne(['client_id' => $client_id]);
}
/**
* @inheritdoc
*/
public function getClientDetails($client_id)
{
$client = $this->getClient($client_id);
if (empty($client)) return [];
return [
"redirect_uri" => $client->redirect_uri, // REQUIRED redirect_uri registered for the client
"client_id" => $client->client_id, // OPTIONAL the client id
"grant_types" => $client->grant_types, // OPTIONAL an array of restricted grant types
"user_id" => $client->user_id, // OPTIONAL the user identifier associated with this client
"scope" => $client->scope, // OPTIONAL the scopes allowed for this client
];
}
/**
* @inheritdoc
*/
public function getClientScope($client_id)
{
$client = $this->getClient($client_id);
if (empty($client)) return null;
return $client->scope;
}
/**
* @inheritdoc
*/
public function checkRestrictedGrantType($client_id, $grant_type)
{
$client = $this->getClient($client_id);
if (empty($client)) return false;
$validGrantTypes = explode(" ", $client->grant_types);
return in_array($grant_type, $validGrantTypes);
}
/**
* @inheritdoc
*/
public function checkClientCredentials($client_id, $client_secret = null)
{
$client = $this->getClient($client_id);
if (empty($client)) return false;
return ($client->client_secret == $client_secret);
}
/**
* @inheritdoc
*/
public function isPublicClient($client_id)
{
return true;
}
'client_credentials' => 'api\common\models\User',
to storageMap and remove refresh_token
from grantTypes. 'modules' => [
'oauth2' => [
'class' => 'filsh\yii2\oauth2server\Module',
'tokenParamName' => 'accessToken',
'tokenAccessLifetime' => 3600 * 3,
'useJwtToken' => true,
'storageMap' => [
'client_credentials' => 'api\common\models\User',
'user_credentials' => 'api\common\models\User',
'public_key' => 'api\storage\PublicKeyStorage',
'access_token' => 'OAuth2\Storage\JwtAccessToken',
],
'grantTypes' => [
// 'client_credentials' => [
// 'class' => 'OAuth2\GrantType\ClientCredentials',
// 'allow_public_clients' => false
// ],
'user_credentials' => [
'class' => 'OAuth2\GrantType\UserCredentials',
],
// 'refresh_token' => [
// 'class' => 'OAuth2\GrantType\RefreshToken',
// 'always_issue_new_refresh_token' => true
// ]
]
],
I hope this additional information helps someone else.
Since I have no commit access I'll fork it up and will consider your solution
I created a fork of this module as promised. I would like to hear your comments as well as your suggestions. (PR are mostly welcome).
@mtangoo @rlmckenney @vzani @ivantree @danDanV1 the fork mentioned by @mtangoo is archived. By the way, the project support is restored.