Path: blob/master/src/applications/auth/adapter/PhutilAuthAdapter.php
12256 views
<?php12/**3* Abstract interface to an identity provider or authentication source, like4* Twitter, Facebook, or Google.5*6* Generally, adapters are handed some set of credentials particular to the7* provider they adapt, and they turn those credentials into standard8* information about the user's identity. For example, the LDAP adapter is given9* a username and password (and some other configuration information), uses them10* to talk to the LDAP server, and produces a username, email, and so forth.11*12* Since the credentials a provider requires are specific to each provider, the13* base adapter does not specify how an adapter should be constructed or14* configured -- only what information it is expected to be able to provide once15* properly configured.16*/17abstract class PhutilAuthAdapter extends Phobject {1819final public function getAccountIdentifiers() {20$result = $this->newAccountIdentifiers();21assert_instances_of($result, 'PhabricatorExternalAccountIdentifier');22return $result;23}2425protected function newAccountIdentifiers() {26$identifiers = array();2728$raw_identifier = $this->getAccountID();29if ($raw_identifier !== null) {30$identifiers[] = $this->newAccountIdentifier($raw_identifier);31}3233return $identifiers;34}3536final protected function newAccountIdentifier($raw_identifier) {37return id(new PhabricatorExternalAccountIdentifier())38->setIdentifierRaw($raw_identifier);39}4041/**42* Get a unique identifier associated with the account.43*44* This identifier should be permanent, immutable, and uniquely identify45* the account. If possible, it should be nonsensitive. For providers that46* have a GUID or PHID value for accounts, these are the best values to use.47*48* You can implement @{method:newAccountIdentifiers} instead if a provider49* is unable to emit identifiers with all of these properties.50*51* If the adapter was unable to authenticate an identity, it should return52* `null`.53*54* @return string|null Unique account identifier, or `null` if authentication55* failed.56*/57public function getAccountID() {58throw new PhutilMethodNotImplementedException();59}606162/**63* Get a string identifying this adapter, like "ldap". This string should be64* unique to the adapter class.65*66* @return string Unique adapter identifier.67*/68abstract public function getAdapterType();697071/**72* Get a string identifying the domain this adapter is acting on. This allows73* an adapter (like LDAP) to act against different identity domains without74* conflating credentials. For providers like Facebook or Google, the adapters75* just return the relevant domain name.76*77* @return string Domain the adapter is associated with.78*/79abstract public function getAdapterDomain();808182/**83* Generate a string uniquely identifying this adapter configuration. Within84* the scope of a given key, all account IDs must uniquely identify exactly85* one identity.86*87* @return string Unique identifier for this adapter configuration.88*/89public function getAdapterKey() {90return $this->getAdapterType().':'.$this->getAdapterDomain();91}929394/**95* Optionally, return an email address associated with this account.96*97* @return string|null An email address associated with the account, or98* `null` if data is not available.99*/100public function getAccountEmail() {101return null;102}103104105/**106* Optionally, return a human readable username associated with this account.107*108* @return string|null Account username, or `null` if data isn't available.109*/110public function getAccountName() {111return null;112}113114115/**116* Optionally, return a URI corresponding to a human-viewable profile for117* this account.118*119* @return string|null A profile URI associated with this account, or120* `null` if the data isn't available.121*/122public function getAccountURI() {123return null;124}125126127/**128* Optionally, return a profile image URI associated with this account.129*130* @return string|null URI for an account profile image, or `null` if one is131* not available.132*/133public function getAccountImageURI() {134return null;135}136137138/**139* Optionally, return a real name associated with this account.140*141* @return string|null A human real name, or `null` if this data is not142* available.143*/144public function getAccountRealName() {145return null;146}147148}149150151