Path: blob/master/src/applications/auth/adapter/PhutilAsanaAuthAdapter.php
12256 views
<?php12/**3* Authentication adapter for Asana OAuth2.4*/5final class PhutilAsanaAuthAdapter extends PhutilOAuthAuthAdapter {67public function getAdapterType() {8return 'asana';9}1011public function getAdapterDomain() {12return 'asana.com';13}1415public function getAccountID() {16// See T13453. The Asana API has changed to string IDs and now returns a17// "gid" field (previously, it returned an "id" field).18return $this->getOAuthAccountData('gid');19}2021public function getAccountEmail() {22return $this->getOAuthAccountData('email');23}2425public function getAccountName() {26return null;27}2829public function getAccountImageURI() {30$photo = $this->getOAuthAccountData('photo', array());31if (is_array($photo)) {32return idx($photo, 'image_128x128');33} else {34return null;35}36}3738public function getAccountURI() {39return null;40}4142public function getAccountRealName() {43return $this->getOAuthAccountData('name');44}4546protected function getAuthenticateBaseURI() {47return 'https://app.asana.com/-/oauth_authorize';48}4950protected function getTokenBaseURI() {51return 'https://app.asana.com/-/oauth_token';52}5354public function getScope() {55return null;56}5758public function getExtraAuthenticateParameters() {59return array(60'response_type' => 'code',61);62}6364public function getExtraTokenParameters() {65return array(66'grant_type' => 'authorization_code',67);68}6970public function getExtraRefreshParameters() {71return array(72'grant_type' => 'refresh_token',73);74}7576public function supportsTokenRefresh() {77return true;78}7980protected function loadOAuthAccountData() {81return id(new PhutilAsanaFuture())82->setAccessToken($this->getAccessToken())83->setRawAsanaQuery('users/me')84->resolve();85}8687}888990