Hello! Immediately ask forgiveness for my English. I tried to configure OAuth2 client authentication. But failed. Here is the code that I use for the test:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <title>Nextcloud Authentication</title> </head> <body>  <?php  $client_id = ''; // Client ID $client_secret = ''; // Client secret $redirect_uri = 'https://example.com/nextcloud/oauth2.php'; // Redirect URIs   $url = 'https://cloud.example.com/index.php/apps/oauth2/authorize';  $params = array( 'redirect_uri' => $redirect_uri, 'response_type' => 'code', 'client_id' => $client_id );  echo $link = '<p><a href="' . $url . '?' . urldecode(http_build_query($params)) . '">Nextcloud Authentication</a></p>';  if (isset($_GET['code'])) { $result = false; echo "<br>code = " . $_GET['code'] . "<br><br>"; $params = array( 'client_id' => $client_id, 'client_secret' => $client_secret, 'redirect_uri' => $redirect_uri, 'grant_type' => 'authorization_code', 'code' => $_GET['code'] );  $url = 'https://cloud.example.com/index.php/apps/oauth2/api/v1/token';  $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, urldecode(http_build_query($params))); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($curl); curl_close($curl); $tokenInfo = json_decode($result, true);  echo "<br><br>" . print_r($tokenInfo); }  ?>  </body> </html> Â
When navigating to the URL âhttps://cloud.example.com/index.php/apps/oauth2/authorizeâ and granting access to the application, everything seems to go fine, after the redirect I get the code in the parameters. But one thing, it throws me out of the account if I was logged in.
Everything would be fine, but when I try to access tocken I get an error. Literally:
"
Internal Server Error
The server was unable to complete your request.
If this happens again, please send the technical details below to the server administrator.
More details can be found in the server log.
Technical details
_ Remote Address: 127.0.0.1_
_ Request ID: skItAuhDOHGbP7ws3XfB_
"
In the Nextcloud log, I get a message like:
{
âreqIdâ: âskItAuhDOHGbP7ws3XfBâ,
âlevelâ: 3,
âtimeâ: â2018-07-04T08:06:53+00:00â,
âremoteAddrâ: â127.0.0.1â,
âuserâ: âââ,
âappâ: âindexâ,
âmethodâ: âPOSTâ,
âurlâ: â/index.php/apps/oauth2/api/v1/tokenâ,
âmessageâ: âException: {âExceptionâ:âOCA\\OAuth2\\Exceptions\\AccessTokenNotFoundExceptionâ,âMessageâ:â",âCodeâ:0,âTraceâ:"#0 \/var\/www\/html\/cloud.example.com\/nextcloud\/apps\/oauth2\/lib\/Controller\/OauthApiController.php(71): OCA\\OAuth2\\Db\\AccessTokenMapper->getByCode(â23fQ\/cc1IXFNKWwâŠâ)\n#1 [internal function]: OCA\\OAuth2\\Controller\\OauthApiController->getToken(*** sensitive parameters replaced ***)\n#2 \/var\/www\/html\/cloud.example.com\/nextcloud\/lib\/private\/AppFramework\/Http\/Dispatcher.php(161): call_user_func_array(Array, Array)\n#3 \/var\/www\/html\/cloud.example.com\/nextcloud\/lib\/private\/AppFramework\/Http\/Dispatcher.php(91): OC\\AppFramework\\Http\\Dispatcher->executeController(Object(OCA\\OAuth2\\Controller\\OauthApiController), âgetTokenâ)\n#4 \/var\/www\/html\/cloud.example.com\/nextcloud\/lib\/private\/AppFramework\/App.php(115): OC\\AppFramework\\Http\\Dispatcher->dispatch(Object(OCA\\OAuth2\\Controller\\OauthApiController), âgetTokenâ)\n#5 \/var\/www\/html\/cloud.example.com\/nextcloud\/lib\/private\/AppFramework\/Routing\/RouteActionHandler.php(47): OC\\AppFramework\\App::main(âOCA\\\\OAuth2\\\\ContâŠâ, âgetTokenâ, Object(OC\\AppFramework\\DependencyInjection\\DIContainer), Array)\n#6 [internal function]: OC\\AppFramework\\Routing\\RouteActionHandler->__invoke(Array)\n#7 \/var\/www\/html\/cloud.example.com\/nextcloud\/lib\/private\/Route\/Router.php(297): call_user_func(Object(OC\\AppFramework\\Routing\\RouteActionHandler), Array)\n#8 \/var\/www\/html\/cloud.example.com\/nextcloud\/lib\/base.php(999): OC\\Route\\Router->match(â\/apps\/oauth2\/apâŠâ)\n#9 \/var\/www\/html\/cloud.example.com\/nextcloud\/index.php(37): OC::handleRequest()\n#10 {main}",âFileâ:"\/var\/www\/html\/cloud.example.com\/nextcloud\/apps\/oauth2\/lib\/Db\/AccessTokenMapper.php",âLineâ:53}",
âuserAgentâ: âââ,
âversionâ: â13.0.2.1â
}
What can be wrong? In Nextcloud, I configured only the OAuth2 client.