Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / auth / adapter / PhutilAuthAdapter.php
blobf8a980313c419d10855eb765831334511c0ff983
1 <?php
3 /**
4 * Abstract interface to an identity provider or authentication source, like
5 * Twitter, Facebook, or Google.
7 * Generally, adapters are handed some set of credentials particular to the
8 * provider they adapt, and they turn those credentials into standard
9 * information about the user's identity. For example, the LDAP adapter is given
10 * a username and password (and some other configuration information), uses them
11 * to talk to the LDAP server, and produces a username, email, and so forth.
13 * Since the credentials a provider requires are specific to each provider, the
14 * base adapter does not specify how an adapter should be constructed or
15 * configured -- only what information it is expected to be able to provide once
16 * properly configured.
18 abstract class PhutilAuthAdapter extends Phobject {
20 final public function getAccountIdentifiers() {
21 $result = $this->newAccountIdentifiers();
22 assert_instances_of($result, 'PhabricatorExternalAccountIdentifier');
23 return $result;
26 protected function newAccountIdentifiers() {
27 $identifiers = array();
29 $raw_identifier = $this->getAccountID();
30 if ($raw_identifier !== null) {
31 $identifiers[] = $this->newAccountIdentifier($raw_identifier);
34 return $identifiers;
37 final protected function newAccountIdentifier($raw_identifier) {
38 return id(new PhabricatorExternalAccountIdentifier())
39 ->setIdentifierRaw($raw_identifier);
42 /**
43 * Get a unique identifier associated with the account.
45 * This identifier should be permanent, immutable, and uniquely identify
46 * the account. If possible, it should be nonsensitive. For providers that
47 * have a GUID or PHID value for accounts, these are the best values to use.
49 * You can implement @{method:newAccountIdentifiers} instead if a provider
50 * is unable to emit identifiers with all of these properties.
52 * If the adapter was unable to authenticate an identity, it should return
53 * `null`.
55 * @return string|null Unique account identifier, or `null` if authentication
56 * failed.
58 public function getAccountID() {
59 throw new PhutilMethodNotImplementedException();
63 /**
64 * Get a string identifying this adapter, like "ldap". This string should be
65 * unique to the adapter class.
67 * @return string Unique adapter identifier.
69 abstract public function getAdapterType();
72 /**
73 * Get a string identifying the domain this adapter is acting on. This allows
74 * an adapter (like LDAP) to act against different identity domains without
75 * conflating credentials. For providers like Facebook or Google, the adapters
76 * just return the relevant domain name.
78 * @return string Domain the adapter is associated with.
80 abstract public function getAdapterDomain();
83 /**
84 * Generate a string uniquely identifying this adapter configuration. Within
85 * the scope of a given key, all account IDs must uniquely identify exactly
86 * one identity.
88 * @return string Unique identifier for this adapter configuration.
90 public function getAdapterKey() {
91 return $this->getAdapterType().':'.$this->getAdapterDomain();
95 /**
96 * Optionally, return an email address associated with this account.
98 * @return string|null An email address associated with the account, or
99 * `null` if data is not available.
101 public function getAccountEmail() {
102 return null;
107 * Optionally, return a human readable username associated with this account.
109 * @return string|null Account username, or `null` if data isn't available.
111 public function getAccountName() {
112 return null;
117 * Optionally, return a URI corresponding to a human-viewable profile for
118 * this account.
120 * @return string|null A profile URI associated with this account, or
121 * `null` if the data isn't available.
123 public function getAccountURI() {
124 return null;
129 * Optionally, return a profile image URI associated with this account.
131 * @return string|null URI for an account profile image, or `null` if one is
132 * not available.
134 public function getAccountImageURI() {
135 return null;
140 * Optionally, return a real name associated with this account.
142 * @return string|null A human real name, or `null` if this data is not
143 * available.
145 public function getAccountRealName() {
146 return null;