-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Line 260 in fb2fedf
| // TODO log data to shadow profile |
if ($this->getuser($jwt_claims['sub'])) return false;
// else add user
$attr['locale'] = $this->utils->get_default_locale($jwt_claims['locale'] ?? 'en') ?? 'en_US';
$transform = new ArrayTransformer();
$transform
->map(destination: 'service.0.uri', source: 'iss')
->map(destination: 'service.0.handle', source: 'preferred_username')
->set(destination: 'service.0.kind', value: 'oidc')
->map(destination: 'service.0._iss', source: 'iss')
->set(destination: 'service.0._iat', value: time())
->map(destination: 'service.0._sub', source: 'sub')
->set(destination: 'service.0.uuid', value: \Ramsey\Uuid\Uuid::uuid4()->toString());
if (array_key_exists('name', $jwt_claims) and $jwt_claims['email'] != "") {
$transform
->map(destination: 'name.0.fn', source: 'name')
->map(destination: 'name.0.given', source: 'given_name')
->map(destination: 'name.0.family', source: 'family_name')
->map(destination: 'name.0._iss', source: 'iss')
->set(destination: 'name.0._iat', value: time())
->map(destination: 'name.0._sub', source: 'sub')
->set(destination: 'name.0.uuid', value: \Ramsey\Uuid\Uuid::uuid4()->toString());
}
if (array_key_exists('email', $jwt_claims) and $jwt_claims['email'] != "") {
$transform
->map(destination: 'email.0.value', source: 'email')
->map(destination: 'email.0._iss', source: 'iss')
->set(destination: 'email.0._iat', value: time())
->map(destination: 'email.0._sub', source: 'sub')
->set(destination: 'email.0._primary', value: 1);
->set(destination: 'email.0.uuid', value: \Ramsey\Uuid\Uuid::uuid4()->toString())
}
if (array_key_exists('website', $jwt_claims) and $jwt_claims['website'] != "") {
$transform
->map(destination: 'uri.0.value', source: 'website')
->set(destination: 'uri.0.kind', value: 'website')
->map(destination: 'uri.0._iss', source: 'iss')
->set(destination: 'uri.0._iat', value: time())
->map(destination: 'uri.0._sub', source: 'sub')
->set(destination: 'uri.0.uuid', value: \Ramsey\Uuid\Uuid::uuid4()->toString());
}
$profile = $transform->toArray($jwt_claims) ?? [];
// TODO log data to shadow profile
if ($jwt_claims['sub']) {
$data["c_uuid"] = $this->db->func('uuid_to_bin(?, true)', [$jwt_claims['sub']]);
$data["c_profile"] = json_encode($profile);
$data["c_attr"] = json_encode($attr);
$data["c_email"] = $jwt_claims['email'] ?? 'NULL';
$data["c_handle"] = $jwt_claims['preferred_username'] ?? 'NULL';
// catch exception here
$domain_uuid = \Ramsey\Uuid\Uuid::uuid4()->toString();
$q = '
INSERT INTO `t_core_domains` (`c_uuid`, `c_primary_owner`, `c_json`, `c_ts_created`, `c_ts_modified`)
SELECT uuid_to_bin(?, true), uuid_to_bin(?, true), ?, now(), now() -- no parentheses!
FROM DUAL -- DUAL is a built-in table with one row
WHERE NOT EXISTS ( select 1 from t_core_domains limit 1 );';
$this->db->rawQuery($q, [
$domain_uuid,
$jwt_claims['sub'],
json_encode( [
'uuid' => $domain_uuid,
'name' => 'Main',
'ownership' => [
[
'_sub' => $jwt_claims['sub'],
'_iat' => time(),
'_primary' => 1
]
],
])
]);
return $this->db->insert('t_core_users', $data);
}
return false;
}