我目前正在尝试安装Yii2扩展来实现OAuth2服务器(https://github.com/Filsh/yii2-oauth2-server)。但是,我继续运行以下错误:
有没有人知道如何安装此扩展程序。我按照给出的指示,但没有提到这个错误。
答案 0 :(得分:3)
Satya是对的。您需要按照repo's description:
中的说明配置oauth2
模块
'oauth2' => [
'class' => 'filsh\yii2\oauth2server\Module',
'options' => [
'token_param_name' => 'accessToken',
'access_lifetime' => 3600 * 24
],
'storageMap' => [
'user_credentials' => '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
]
],
]
我已成功配置此扩展程序并创建Yii2 Rest API template with OAuth2 server
https://github.com/ikaras/yii2-oauth2-rest-template - 随意使用。此代码还有一些演示数据(使用示例)和scopes
对控制器的支持。
答案 1 :(得分:1)
在config / main.php的'modules'部分添加'oauth2'配置。 它可能有用
答案 2 :(得分:0)
在modules部分下的confin / main.php文件下使用此配置。
// serialize v2 using the new app
var v2 = new ClassV2() { Value = EnumV2.Three };
var v2data = Serialize(v2);
// try to deserialize this inside the old app to v1
var v1roundtrip = Deserialize<ClassV1>(v2data);
];
答案 3 :(得分:0)
在范围问题上找到解决方案my-self,也许它对某人有用 - 在配置中用**标记:
'modules' => [
'oauth2' => [
'class' => 'filsh\yii2\oauth2server\Module',
'tokenParamName' => 'accessToken',
'tokenAccessLifetime' => 3600 * 24,
'storageMap' => [
'client_credentials' => 'app\models\User',
'user_credentials' => 'app\models\User',
**'scope' => 'app\models\User',**
],
'grantTypes' => [
'client_credentials' => [
'class' => '\OAuth2\GrantType\ClientCredentials',
'allow_public_clients' => false,
'always_issue_new_refresh_token' => true
],
'user_credentials' => [
'class' => 'OAuth2\GrantType\UserCredentials',
],
'refresh_token' => [
'class' => 'OAuth2\GrantType\RefreshToken',
'always_issue_new_refresh_token' => true
]
]
]
],