@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
3/**
4 * Authentication adapter for WordPress.com OAuth2.
5 */
6final class PhutilWordPressAuthAdapter extends PhutilOAuthAuthAdapter {
7
8 public function getAdapterType() {
9 return 'wordpress';
10 }
11
12 public function getAdapterDomain() {
13 return 'wordpress.com';
14 }
15
16 public function getAccountID() {
17 return $this->getOAuthAccountData('ID');
18 }
19
20 public function getAccountEmail() {
21 return $this->getOAuthAccountData('email');
22 }
23
24 public function getAccountName() {
25 return $this->getOAuthAccountData('username');
26 }
27
28 public function getAccountImageURI() {
29 return $this->getOAuthAccountData('avatar_URL');
30 }
31
32 public function getAccountURI() {
33 return $this->getOAuthAccountData('profile_URL');
34 }
35
36 public function getAccountRealName() {
37 return $this->getOAuthAccountData('display_name');
38 }
39
40 protected function getAuthenticateBaseURI() {
41 return 'https://public-api.wordpress.com/oauth2/authorize';
42 }
43
44 protected function getTokenBaseURI() {
45 return 'https://public-api.wordpress.com/oauth2/token';
46 }
47
48 public function getScope() {
49 return 'user_read';
50 }
51
52 public function getExtraAuthenticateParameters() {
53 return array(
54 'response_type' => 'code',
55 'blog_id' => 0,
56 );
57 }
58
59 public function getExtraTokenParameters() {
60 return array(
61 'grant_type' => 'authorization_code',
62 );
63 }
64
65 protected function loadOAuthAccountData() {
66 return id(new PhutilWordPressFuture())
67 ->setClientID($this->getClientID())
68 ->setAccessToken($this->getAccessToken())
69 ->setRawWordPressQuery('/me/')
70 ->resolve();
71 }
72
73}