Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / auth / provider / PhabricatorAsanaAuthProvider.php
blob4067e522af44bc51812b00a3bf1bd138a6c2fe55
1 <?php
3 final class PhabricatorAsanaAuthProvider
4 extends PhabricatorOAuth2AuthProvider
5 implements DoorkeeperRemarkupURIInterface {
7 public function getProviderName() {
8 return pht('Asana');
11 protected function getProviderConfigurationHelp() {
12 $app_uri = PhabricatorEnv::getProductionURI('/');
13 $login_uri = PhabricatorEnv::getURI($this->getLoginURI());
15 return pht(
16 "To configure Asana OAuth, create a new application here:".
17 "\n\n".
18 "https://app.asana.com/-/account_api".
19 "\n\n".
20 "When creating your application, use these settings:".
21 "\n\n".
22 " - **App URL:** Set this to: `%s`\n".
23 " - **Redirect URL:** Set this to: `%s`".
24 "\n\n".
25 "After completing configuration, copy the **Client ID** and ".
26 "**Client Secret** to the fields above.",
27 $app_uri,
28 $login_uri);
31 protected function newOAuthAdapter() {
32 return new PhutilAsanaAuthAdapter();
35 protected function getLoginIcon() {
36 return 'Asana';
39 public static function getAsanaProvider() {
40 $providers = self::getAllEnabledProviders();
42 foreach ($providers as $provider) {
43 if ($provider instanceof PhabricatorAsanaAuthProvider) {
44 return $provider;
48 return null;
51 /* -( DoorkeeperRemarkupURIInterface )------------------------------------- */
53 public function getDoorkeeperURIRef(PhutilURI $uri) {
54 $uri_string = phutil_string_cast($uri);
56 $pattern = '(https://app\\.asana\\.com/0/(\\d+)/(\\d+))';
57 $matches = null;
58 if (!preg_match($pattern, $uri_string, $matches)) {
59 return null;
62 if (strlen($uri->getFragment())) {
63 return null;
66 if ($uri->getQueryParamsAsPairList()) {
67 return null;
70 $context_id = $matches[1];
71 $task_id = $matches[2];
73 return id(new DoorkeeperURIRef())
74 ->setURI($uri)
75 ->setApplicationType(DoorkeeperBridgeAsana::APPTYPE_ASANA)
76 ->setApplicationDomain(DoorkeeperBridgeAsana::APPDOMAIN_ASANA)
77 ->setObjectType(DoorkeeperBridgeAsana::OBJTYPE_TASK)
78 ->setObjectID($task_id);