@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
at recaptime-dev/main 88 lines 1.9 kB view raw
1<?php 2 3/** 4 * Authentication adapter for Asana OAuth2. 5 */ 6final class PhutilAsanaAuthAdapter extends PhutilOAuthAuthAdapter { 7 8 public function getAdapterType() { 9 return 'asana'; 10 } 11 12 public function getAdapterDomain() { 13 return 'asana.com'; 14 } 15 16 public function getAccountID() { 17 // See T13453. The Asana API has changed to string IDs and now returns a 18 // "gid" field (previously, it returned an "id" field). 19 return $this->getOAuthAccountData('gid'); 20 } 21 22 public function getAccountEmail() { 23 return $this->getOAuthAccountData('email'); 24 } 25 26 public function getAccountName() { 27 return null; 28 } 29 30 public function getAccountImageURI() { 31 $photo = $this->getOAuthAccountData('photo', array()); 32 if (is_array($photo)) { 33 return idx($photo, 'image_128x128'); 34 } else { 35 return null; 36 } 37 } 38 39 public function getAccountURI() { 40 return null; 41 } 42 43 public function getAccountRealName() { 44 return $this->getOAuthAccountData('name'); 45 } 46 47 protected function getAuthenticateBaseURI() { 48 return 'https://app.asana.com/-/oauth_authorize'; 49 } 50 51 protected function getTokenBaseURI() { 52 return 'https://app.asana.com/-/oauth_token'; 53 } 54 55 public function getScope() { 56 return null; 57 } 58 59 public function getExtraAuthenticateParameters() { 60 return array( 61 'response_type' => 'code', 62 ); 63 } 64 65 public function getExtraTokenParameters() { 66 return array( 67 'grant_type' => 'authorization_code', 68 ); 69 } 70 71 public function getExtraRefreshParameters() { 72 return array( 73 'grant_type' => 'refresh_token', 74 ); 75 } 76 77 public function supportsTokenRefresh() { 78 return true; 79 } 80 81 protected function loadOAuthAccountData() { 82 return id(new PhutilAsanaFuture()) 83 ->setAccessToken($this->getAccessToken()) 84 ->setRawAsanaQuery('users/me') 85 ->resolve(); 86 } 87 88}