@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<?php
2
3final class PhabricatorAsanaAuthProvider
4 extends PhabricatorOAuth2AuthProvider
5 implements DoorkeeperRemarkupURIInterface {
6
7 public function getProviderName() {
8 return pht('Asana');
9 }
10
11 protected function getProviderConfigurationHelp() {
12 $app_uri = PhabricatorEnv::getProductionURI('/');
13 $login_uri = PhabricatorEnv::getURI($this->getLoginURI());
14
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);
29 }
30
31 protected function newOAuthAdapter() {
32 return new PhutilAsanaAuthAdapter();
33 }
34
35 protected function getLoginIcon() {
36 return 'Asana';
37 }
38
39 public static function getAsanaProvider() {
40 $providers = self::getAllEnabledProviders();
41
42 foreach ($providers as $provider) {
43 if ($provider instanceof PhabricatorAsanaAuthProvider) {
44 return $provider;
45 }
46 }
47
48 return null;
49 }
50
51/* -( DoorkeeperRemarkupURIInterface )------------------------------------- */
52
53 public function getDoorkeeperURIRef(PhutilURI $uri) {
54 $uri_string = phutil_string_cast($uri);
55
56 $pattern = '(https://app\\.asana\\.com/0/(\\d+)/(\\d+))';
57 $matches = null;
58 if (!preg_match($pattern, $uri_string, $matches)) {
59 return null;
60 }
61
62 if (strlen($uri->getFragment())) {
63 return null;
64 }
65
66 if ($uri->getQueryParamsAsPairList()) {
67 return null;
68 }
69
70 $context_id = $matches[1];
71 $task_id = $matches[2];
72
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);
79 }
80
81}