2015-02-03 34 views

Trả lời

1

Thêm cấu hình cho 'oauth2' trong phần 'mô-đun' của config/main.php. Có thể hoạt động

3

Satya là đúng. Bạn cần phải cấu hình oauth2 mô-đun như mô tả trên repo's description:

'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 
     ] 
    ], 
] 

Tôi đã cấu hình phần mở rộng này thành công và tạo Yii2 Rest API template with OAuth2 serverhttps://github.com/ikaras/yii2-oauth2-rest-template - thoải mái sử dụng. Ngoài ra mã này có một số dữ liệu demo (ví dụ về sử dụng) và hỗ trợ của scopes cho bộ điều khiển.

+1

Link chỉ câu trả lời không được hoan nghênh trên StackOverflow. Vui lòng thêm phần cần thiết để trả lời. – arogachev

0

Sử dụng cấu hình này trong tệp confin/main.php của bạn trong phần mô-đun.

'oauth2' => [ 
'class'    => 'filsh\yii2\oauth2server\Module', 
'tokenParamName'  => 'token', 
'tokenAccessLifetime' => '100800', // Expiry Time 
'storageMap'   => [ 
    'user_credentials' => 'common\models\User', // This Should be your model name 
], 
'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, 
     'refresh_token_lifetime'   => '100800', 
    ], 
], 

];

0

Tìm thấy giải pháp của tôi-tự về vấn đề phạm vi, có thể nó sẽ có ích cho một ai đó - được đánh dấu bằng ** trong config:

'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 
      ] 
     ] 
    ] 
], 
Các vấn đề liên quan