2015-02-03 10 views

risposta

1

Aggiungi la configurazione 'oauth2' nella sezione 'modules' di config/main.php. Potrebbe funzionare

3

Satya ha ragione. È necessario configurare il modulo oauth2 come descritto a 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 
     ] 
    ], 
] 

Ho configurato questa estensione con successo e ha creato Yii2 Rest API template with OAuth2 serverhttps://github.com/ikaras/yii2-oauth2-rest-template - sentitevi liberi di utilizzare. Anche questo codice ha alcuni dati demo (esempi di utilizzo) e il supporto di scopes per i controller.

+1

link solo risposte non vengono accolti su StackOverflow. Si prega di aggiungere la parte essenziale per rispondere. – arogachev

0

Utilizzare questa configurazione sotto il file confin/main.php nella sezione moduli.

'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

soluzione trovata my-self sul tema portata, forse sarà utile per qualcuno - contrassegnati con ** in 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 
      ] 
     ] 
    ] 
],