我想为已有大型数据库(包括用户表)的现有Web应用程序开发API。内容检索端点的OAuth2.0实现已经适用于范围和我需要的一切。
不幸的是,到目前为止我还无法掌握如何实现登录。 API端点可以工作,但现在我也想在这里实现OAuth2。据我所知,我正在使用的库的示例,它提供了自己的用户表。 https://bshaffer.github.io/oauth2-server-php-docs/grant-types/user-credentials/
到目前为止我的代码看起来像这样:
$app->put('/login', function() use ($app) {
global $feedback, $sess_id, $server, $response;
$request = OAuth2\Request::createFromGlobals();
$response = new OAuth2\Response();
$scopeRequired = 'UserAccess';
if (!$server->verifyResourceRequest($request, $response, $scopeRequired)) {
// if the scope required is different from what the token allows, this will send a "401 insufficient_scope" error
$response->send();
die;
}
// check for required params
verifyRequiredParams(array('un', 'pw', 'cc'));
// reading post params
$user_name = $app->request()->put('un');
$password = $app->request()->put('pw');
$area_provided['cc']= $app->request()->put('cc');
$response = array();
user_login($user_name,$password, true, $area_provided);
$userdata = get_userdata_2();
if (isset($feedback) AND $feedback == 'ok'){
$response["error"] = false;
// $response['user_name'] = $userdata['user_name'];
// $response['email'] = $userdata['email'];
// $response['apiKey'] = $userdata['api_key'];
$response['sess_id'] = $sess_id;
}elseif ($feedback == 'max_login_tries'){ // client login
$response['error'] = true;
$response['message'] = "Maximale Anzahl von Versuchen ereicht";
}
elseif($feedback == 'nopass'){
$response['error'] = true;
$response['message'] = "Bitte geben Sie ihr Passwort an";
}
elseif($feedback == 'user_unknown'){
$response['error'] = true;
$response['message'] = "Dieser Benutzername ist uns nicht bekannt";
}
elseif($feedback == 'wrong_password'){
$response['error'] = true;
$response['message'] = "Das Passwort ist falsch";
}
elseif($feedback == 'deactivated'){
$response['error'] = true;
$response['message'] = "Ihr Benutzerkonto wurde deaktiviert";
}
elseif($feedback == 'wrong_country'){
$response['error'] = true;
$response['message'] = "Ihr Benutzerkonto gilt für ein anderes Land";
}
else{ // other
$response['error'] = true;
$response['message'] = "Unbekannter Fehler";
}
echoRespnse(200, $response);
});
我怎么可能
感谢您对此有任何帮助!