@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 Twitch.tv OAuth2.
5 */
6final class PhutilTwitchAuthAdapter extends PhutilOAuthAuthAdapter {
7
8 public function getAdapterType() {
9 return 'twitch';
10 }
11
12 public function getAdapterDomain() {
13 return 'twitch.tv';
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('login');
26 }
27
28 public function getAccountImageURI() {
29 return $this->getOAuthAccountData('profile_image_url');
30 }
31
32 public function getAccountURI() {
33 $name = $this->getAccountName();
34 if ($name) {
35 return 'https://www.twitch.tv/'.$name;
36 }
37 return null;
38 }
39
40 public function getAccountRealName() {
41 return $this->getOAuthAccountData('display_name');
42 }
43
44 protected function getAuthenticateBaseURI() {
45 return 'https://id.twitch.tv/oauth2/authorize';
46 }
47
48 protected function getTokenBaseURI() {
49 return 'https://id.twitch.tv/oauth2/token';
50 }
51
52 public function getScope() {
53 return 'user_read';
54 }
55
56 public function getExtraAuthenticateParameters() {
57 return array(
58 'response_type' => 'code',
59 );
60 }
61
62 public function getExtraTokenParameters() {
63 return array(
64 'grant_type' => 'authorization_code',
65 );
66 }
67
68 protected function loadOAuthAccountData() {
69 return id(new PhutilTwitchFuture())
70 ->setClientID($this->getClientID())
71 ->setAccessToken($this->getAccessToken())
72 ->setRawTwitchQuery('users')
73 ->resolve();
74 }
75
76}