]> git.mxchange.org Git - friendica.git/commitdiff
API: Added OAuth revoke, adding documentation to parameters
authorMichael <heluecht@pirati.ca>
Wed, 16 Jun 2021 19:24:44 +0000 (19:24 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 16 Jun 2021 19:24:44 +0000 (19:24 +0000)
src/Module/OAuth/Authorize.php
src/Module/OAuth/Revoke.php
src/Module/OAuth/Token.php

index b2792c598f70dc2300aeec1f6a2db60ca8d16cfe..cf5187d947fbea804027c7da0df9d7b9383fa5b5 100644 (file)
@@ -41,11 +41,12 @@ class Authorize extends BaseApi
        public static function rawContent(array $parameters = [])
        {
                $request = self::getRequest([
-                       'response_type' => '',
-                       'client_id'     => '',
+                       'force_login'   => '', // Forces the user to re-login, which is necessary for authorizing with multiple accounts from the same instance.
+                       'response_type' => '', // Should be set equal to "code".
+                       'client_id'     => '', // Client ID, obtained during app registration.
                        'client_secret' => '', // Isn't normally provided. We will use it if present.
-                       'redirect_uri'  => '',
-                       'scope'         => 'read',
+                       'redirect_uri'  => '', // Set a URI to redirect the user to. If this parameter is set to "urn:ietf:wg:oauth:2.0:oob" then the authorization code will be shown instead. Must match one of the redirect URIs declared during app registration.
+                       'scope'         => 'read', // List of requested OAuth scopes, separated by spaces (or by pluses, if using query parameters). Must be a subset of scopes declared during app registration. If not provided, defaults to "read".
                        'state'         => '',
                ]);
 
index c64193243730502f94e4495e579eea98c49ca576..519e79db015f449d60543541bbc85128595faf55 100644 (file)
 
 namespace Friendica\Module\OAuth;
 
+use Friendica\Core\Logger;
+use Friendica\Core\System;
+use Friendica\Database\DBA;
+use Friendica\DI;
 use Friendica\Module\BaseApi;
 
 /**
@@ -30,6 +34,20 @@ class Revoke extends BaseApi
 {
        public static function post(array $parameters = [])
        {
-               self::unsupported('post');
+               $request = self::getRequest([
+                       'client_id'     => '', // Client ID, obtained during app registration
+                       'client_secret' => '', // Client secret, obtained during app registration
+                       'token'         => '', // The previously obtained token, to be invalidated
+               ]);
+
+               $condition = ['client_id' => $request['client_id'], 'client_secret' => $request['client_secret'], 'access_token' => $request['token']];
+               $token = DBA::selectFirst('application-view', ['id'], $condition);
+               if (empty($token['id'])) {
+                       Logger::warning('Token not found', $condition);
+                       DI::mstdnError()->Unauthorized();
+               }
+
+               DBA::delete('application-token', ['application-id' => $token['id']]);
+               System::jsonExit([]);
        }
 }
index 3a8be825ff9089b29272df5184c5db0023c8373f..715cabeaf2ea3ffcff577a7467f3daee8ac97dfe 100644 (file)
@@ -37,11 +37,12 @@ class Token extends BaseApi
        public static function post(array $parameters = [])
        {
                $request = self::getRequest([
-                       'grant_type'    => '',
-                       'code'          => '',
-                       'redirect_uri'  => '',
-                       'client_id'     => '',
-                       'client_secret' => '',
+                       'client_id'     => '', // Client ID, obtained during app registration
+                       'client_secret' => '', // Client secret, obtained during app registration
+                       'redirect_uri'  => '', // Set a URI to redirect the user to. If this parameter is set to "urn:ietf:wg:oauth:2.0:oob" then the token will be shown instead. Must match one of the redirect URIs declared during app registration.
+                       'scope'         => 'read', // List of requested OAuth scopes, separated by spaces. Must be a subset of scopes declared during app registration. If not provided, defaults to "read".
+                       'code'          => '', // A user authorization code, obtained via /oauth/authorize
+                       'grant_type'    => '', // Set equal to "authorization_code" if code is provided in order to gain user-level access. Otherwise, set equal to "client_credentials" to obtain app-level access only.
                ]);
 
                // AndStatus transmits the client data in the AUTHORIZATION header field, see https://github.com/andstatus/andstatus/issues/530