@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Try to diagnose App Login only for OAuth providers which support it

Summary: We currently try to do "app login" for all OAuth providers, but not all of them support it in a meaningful way. Particularly, it always fails for Google.

Test Plan: Ran google diagnostics on a working config, no longer got a diagnostic failure.

Reviewers: btrahan, vrana, csilvers

Reviewed By: csilvers

CC: aran

Differential Revision: https://secure.phabricator.com/D2377

+51 -33
+35 -33
src/applications/auth/controller/oauthdiagnostics/PhabricatorOAuthDiagnosticsController.php
··· 131 131 } 132 132 } 133 133 134 - $test_uri = new PhutilURI($provider->getTokenURI()); 135 - $test_uri->setQueryParams( 136 - array( 137 - 'client_id' => $client_id, 138 - 'client_secret' => $client_secret, 139 - 'grant_type' => 'client_credentials', 140 - )); 134 + if ($provider->shouldDiagnoseAppLogin()) { 135 + $test_uri = new PhutilURI($provider->getTokenURI()); 136 + $test_uri->setQueryParams( 137 + array( 138 + 'client_id' => $client_id, 139 + 'client_secret' => $client_secret, 140 + 'grant_type' => 'client_credentials', 141 + )); 141 142 142 - $token_value = @file_get_contents($test_uri, false, $timeout); 143 - $token_strict = @file_get_contents($test_uri, false, $timeout_strict); 144 - if ($token_value === false) { 145 - $results['App Login'] = array( 146 - $res_no, 147 - null, 148 - "Unable to perform an application login with your Application ID and ". 149 - "Application Secret. You may have mistyped or misconfigured them; ". 150 - "{$name} may have revoked your authorization; or {$name} may be ". 151 - "having technical problems."); 152 - } else { 153 - if ($token_strict) { 143 + $token_value = @file_get_contents($test_uri, false, $timeout); 144 + $token_strict = @file_get_contents($test_uri, false, $timeout_strict); 145 + if ($token_value === false) { 154 146 $results['App Login'] = array( 155 - $res_ok, 156 - '(A Valid Token)', 157 - "Raw application login to {$name} works."); 147 + $res_no, 148 + null, 149 + "Unable to perform an application login with your Application ID ". 150 + "and Application Secret. You may have mistyped or misconfigured ". 151 + "them; {$name} may have revoked your authorization; or {$name} may ". 152 + "be having technical problems."); 158 153 } else { 159 - $data = json_decode($token_value, true); 160 - if (!is_array($data)) { 154 + if ($token_strict) { 161 155 $results['App Login'] = array( 162 - $res_no, 163 - $token_value, 164 - "Application Login failed but the provider did not respond ". 165 - "with valid JSON error information. {$name} may be experiencing ". 166 - "technical problems."); 156 + $res_ok, 157 + '(A Valid Token)', 158 + "Raw application login to {$name} works."); 167 159 } else { 168 - $results['App Login'] = array( 169 - $res_no, 170 - null, 171 - "Application Login failed with error: ".$token_value); 160 + $data = json_decode($token_value, true); 161 + if (!is_array($data)) { 162 + $results['App Login'] = array( 163 + $res_no, 164 + $token_value, 165 + "Application Login failed but the provider did not respond ". 166 + "with valid JSON error information. {$name} may be experiencing ". 167 + "technical problems."); 168 + } else { 169 + $results['App Login'] = array( 170 + $res_no, 171 + null, 172 + "Application Login failed with error: ".$token_value); 173 + } 172 174 } 173 175 } 174 176 }
+8
src/applications/auth/oauth/provider/base/PhabricatorOAuthProvider.php
··· 45 45 return array(); 46 46 } 47 47 48 + /** 49 + * If the provider supports application login, the diagnostics page can try 50 + * to test it. Most providers do not support this (Facebook does). 51 + */ 52 + public function shouldDiagnoseAppLogin() { 53 + return false; 54 + } 55 + 48 56 abstract public function getTokenURI(); 49 57 50 58 /**
+4
src/applications/auth/oauth/provider/facebook/PhabricatorOAuthProviderFacebook.php
··· 118 118 return $this->userData['name']; 119 119 } 120 120 121 + public function shouldDiagnoseAppLogin() { 122 + return true; 123 + } 124 + 121 125 }
+4
src/applications/auth/oauth/provider/github/PhabricatorOAuthProviderGitHub.php
··· 118 118 return idx($this->userData, 'name'); 119 119 } 120 120 121 + public function shouldDiagnoseAppLogin() { 122 + return true; 123 + } 124 + 121 125 }