Comments (16)
+1. Would it be?
foreach($this->storageMap as $name=>$class) { $storages[$name] = \Yii::$container->get($class); }
from yii2-oauth2-server.
+1
foreach($this->storageMap as $name=>$class) { $storages[$name] = \Yii::$container->get($class); }
This solution worked for me, I believe a fix is needed
from yii2-oauth2-server.
Referencing my comment on #39 (comment)
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
]
]
]
],
from yii2-oauth2-server.
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.
from yii2-oauth2-server.
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.
from yii2-oauth2-server.
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
from yii2-oauth2-server.
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
from yii2-oauth2-server.
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?
from yii2-oauth2-server.
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.
from yii2-oauth2-server.
@rlmckenney did you run composer update? Ca you post composer.json file?
from yii2-oauth2-server.
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.
from yii2-oauth2-server.
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?
from yii2-oauth2-server.
After reading the code and some further experimentation, I was able to get things working. Here is what I did ...
- Use
"filsh/yii2-oauth2-server": "2.0.1.x-dev@dev"
in my composer.json as discussed above. - Update \filsh\yii2\oauth2server\Module.php at line 104 to replace
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);
}
- Add the following methods to the User class so that it implements the
\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;
}
- Update the modules section of main config to add
'client_credentials' => 'api\common\models\User',
to storageMap and removerefresh_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.
from yii2-oauth2-server.
Since I have no commit access I'll fork it up and will consider your solution
from yii2-oauth2-server.
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).
https://github.com/hosannahighertech/yii2-oauth2-server
from yii2-oauth2-server.
@mtangoo @rlmckenney @vzani @ivantree @danDanV1 the fork mentioned by @mtangoo is archived. By the way, the project support is restored.
from yii2-oauth2-server.
Related Issues (20)
- Is this project still live? HOT 3
- yii 2.0.13 has erros!~ HOT 7
- Authorization url
- 不能使用授权码认证(AuthorizationCode) HOT 1
- oauth2/token 使用最新的yii2版本,访问报错 HOT 1
- Module.php getRequest() function has an error after yii 2.0.13 HOT 5
- How to install and run HOT 6
- where is a example? HOT 1
- Add 'auth_code_lifetime' support to config HOT 1
- Declaration of m140501_075311_add_oauth2_server::primaryKey($columns) should be compatible with yii\db\Migration::primaryKey($length = NULL) HOT 2
- document error for migration HOT 1
- Calling unknown method: filsh\yii2\oauth2server\Module::handleAuthorizeRequest() HOT 2
- How to use scopes?
- How to add own field in login responce? HOT 1
- Not able to generate token getting handleAuthorizeRequest error HOT 4
- Invalid credentials
- Need more example with Yii2 Auth client integration
- How to use this extension with official Yii2 AuthClient ? HOT 1
- How to implement OpenID Connect ?
- ASK, how to get the public key to show to specific url HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yii2-oauth2-server.