-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathauthzero.api.php
More file actions
54 lines (49 loc) · 1.45 KB
/
authzero.api.php
File metadata and controls
54 lines (49 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* @file
* Hooks specific to the Authzero module.
*/
use Drupal\user\Entity\User;
/**
* @addtogroup hooks
* @{
*/
/**
* Hook invoked just before authzero module validates the user.
*
* @param array $authUserDetails
* A renderable array representing the user details from authzero.
* $user = [
* 'nickname' => 'abc',
* 'name' => 'abc',
* 'picture' => 'url to picture added in auth0',
* 'updated_at' => 2022-10-01T12:17:27.938Z,
* 'email' => 'abc@xyz.com',
* 'email_verified' => 1 || 0,
* 'iss' => 'Domain of auth0 application',
* 'sub' => 'auth0|61e3f37eb1392e00699aacc4',
* 'aud' => 'IJmS0Sw41snjCP2OS5pzAqCI1C1zygzj',
* 'iat' => '1664626668',
* 'exp' => '1664626668',
* 'acr' => 'http://schemas.openid.net/pape/policies/2007/06/multi-factor',
* 'amr' => [],
* 'sid' => 8FfPt9kf8aQpgKIZXvEXIcMG0tkXfWM1
* 'nonce' => ed02edcbcefb71a2902d65f9ab729a14
* ];.
*/
function hook_authzero_pre_validate_user(array $authUserDetails = []) {
if (isset($authUserDetails['email']) && !empty($authUserDetails['email'])) {
$user = User::create();
$user->setPassword($authUserDetails['email'] . '.' . time());
$user->enforceIsNew();
$user->setEmail($authUserDetails['email']);
$user->setUsername($authUserDetails['name']);
$user->set("init", 'mail');
$user->activate();
// Save user account.
$user->save();
}
}
/**
* @} End of "addtogroup hooks".
*/