class Authmap in External Authentication 8
Same name in this branch
- 8 src/Authmap.php \Drupal\externalauth\Authmap
- 8 src/Plugin/migrate/source/Authmap.php \Drupal\externalauth\Plugin\migrate\source\Authmap
- 8 src/Plugin/migrate/destination/Authmap.php \Drupal\externalauth\Plugin\migrate\destination\Authmap
Same name and namespace in other branches
- 2.0.x src/Authmap.php \Drupal\externalauth\Authmap
Class Authmap.
@package Drupal\externalauth
Hierarchy
- class \Drupal\externalauth\Authmap implements AuthmapInterface
Expanded class hierarchy of Authmap
1 file declares its use of Authmap
- AuthmapTest.php in tests/
src/ Unit/ AuthmapTest.php
3 string references to 'Authmap'
- d6_authmap.yml in migration_templates/
d6_authmap.yml - migration_templates/d6_authmap.yml
- d7_authmap.yml in migration_templates/
d7_authmap.yml - migration_templates/d7_authmap.yml
- externalauth.services.yml in ./
externalauth.services.yml - externalauth.services.yml
1 service uses Authmap
File
- src/
Authmap.php, line 13
Namespace
Drupal\externalauthView source
class Authmap implements AuthmapInterface {
/**
* The connection object used for this data.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* {@inheritdoc}
*
* @param \Drupal\Core\Database\Connection $connection
* The connection object used for this data.
*/
public function __construct(Connection $connection) {
$this->connection = $connection;
}
/**
* {@inheritdoc}
*/
public function save(UserInterface $account, $provider, $authname, $data = NULL) {
if (!is_scalar($data)) {
$data = serialize($data);
}
// If a mapping (for the same provider) from this authname to a different
// account already exists, this throws an exception. If a mapping (for the
// same provider) to this account already exists, the currently stored
// authname is overwritten.
$this->connection
->merge('authmap')
->keys([
'uid' => $account
->id(),
'provider' => $provider,
])
->fields([
'authname' => $authname,
'data' => $data,
])
->execute();
}
/**
* {@inheritdoc}
*/
public function get($uid, $provider) {
$authname = $this->connection
->select('authmap', 'am')
->fields('am', [
'authname',
])
->condition('uid', $uid)
->condition('provider', $provider)
->range(0, 1)
->execute()
->fetchObject();
if ($authname) {
return $authname->authname;
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function getAuthData($uid, $provider) {
$data = $this->connection
->select('authmap', 'am')
->fields('am', [
'authname',
'data',
])
->condition('uid', $uid)
->condition('provider', $provider)
->range(0, 1)
->execute()
->fetchAssoc();
return $data;
}
/**
* {@inheritdoc}
*/
public function getAll($uid) {
$query = $this->connection
->select('authmap', 'am')
->fields('am', [
'provider',
'authname',
])
->condition('uid', $uid)
->orderBy('provider', 'ASC')
->execute();
$result = $query
->fetchAllAssoc('provider');
if ($result) {
foreach ($result as $provider => $data) {
$result[$provider] = $data->authname;
}
}
return $result;
}
/**
* {@inheritdoc}
*/
public function getUid($authname, $provider) {
$authname = $this->connection
->select('authmap', 'am')
->fields('am', [
'uid',
])
->condition('authname', $authname)
->condition('provider', $provider)
->range(0, 1)
->execute()
->fetchObject();
if ($authname) {
return $authname->uid;
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function delete($uid, $provider = NULL) {
$query = $this->connection
->delete('authmap')
->condition('uid', $uid);
if ($provider) {
$query
->condition('provider', $provider);
}
$query
->execute();
}
/**
* {@inheritdoc}
*/
public function deleteProvider($provider) {
$this->connection
->delete('authmap')
->condition('provider', $provider)
->execute();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Authmap:: |
protected | property | The connection object used for this data. | |
Authmap:: |
public | function |
Delete authmap entries for a given Drupal user ID. Overrides AuthmapInterface:: |
|
Authmap:: |
public | function |
Delete all authmap entries for a given provider. Overrides AuthmapInterface:: |
|
Authmap:: |
public | function |
Get the external authname for a given user ID. Overrides AuthmapInterface:: |
|
Authmap:: |
public | function |
Get all external authnames for a given user ID. Overrides AuthmapInterface:: |
|
Authmap:: |
public | function |
Get the external authname & extra data for a given user ID. Overrides AuthmapInterface:: |
|
Authmap:: |
public | function |
Get a Drupal user ID based on an authname. Overrides AuthmapInterface:: |
|
Authmap:: |
public | function |
Save an external authname for a given Drupal user. Overrides AuthmapInterface:: |
|
Authmap:: |
public | function |