Commit 45f85294 authored by dbourdere's avatar dbourdere 🤸
Browse files

oubli de push les derniere modif

parent 17ad6cb6
...@@ -14,12 +14,9 @@ class User implements UserInterface, JsonSerializable ...@@ -14,12 +14,9 @@ class User implements UserInterface, JsonSerializable
protected $id; protected $id;
protected $email; protected $email;
protected $givenName; protected $givenName;
protected $familyName;
protected $username;
protected $picture; protected $picture;
protected $locale; protected $companyId;
protected $company; protected $subscriptions;
protected $services;
protected $stripeCustomerId; protected $stripeCustomerId;
protected $roles; protected $roles;
...@@ -28,16 +25,6 @@ class User implements UserInterface, JsonSerializable ...@@ -28,16 +25,6 @@ class User implements UserInterface, JsonSerializable
$this->roles = ["ROLE_USER"]; $this->roles = ["ROLE_USER"];
} }
public function setServices($services)
{
$this->services = $services;
}
public function getServices()
{
return $this->services;
}
/** /**
* @return mixed * @return mixed
*/ */
...@@ -57,44 +44,6 @@ class User implements UserInterface, JsonSerializable ...@@ -57,44 +44,6 @@ class User implements UserInterface, JsonSerializable
return $this; return $this;
} }
/**
* @return mixed
*/
public function getFamilyName()
{
return $this->familyName;
}
/**
* @param mixed $familyName
*
* @return User
*/
public function setFamilyName($familyName): User
{
$this->familyName = $familyName;
return $this;
}
/**
* @return mixed
*/
public function getUsername()
{
return $this->username;
}
/**
* @param mixed $username
*
* @return User
*/
public function setUsername($username): User
{
$this->username = $username;
return $this;
}
/** /**
* @param mixed $email * @param mixed $email
* *
...@@ -137,79 +86,81 @@ class User implements UserInterface, JsonSerializable ...@@ -137,79 +86,81 @@ class User implements UserInterface, JsonSerializable
/** /**
* @return mixed * @return mixed
*/ */
public function getLocale() public function getCompanyId()
{ {
return $this->locale; return $this->companyId;
} }
/** /**
* @param mixed $locale * @param $companyId
* *
* @return User * @return User
*/ */
public function setLocale($locale): User public function setCompanyId($companyId): User
{ {
$this->locale = $locale; $this->companyId = $companyId;
return $this; return $this;
} }
/** /**
* @return mixed * @return mixed
*/ */
public function getCompany() public function getStripeCustomerId()
{ {
return $this->company; return $this->stripeCustomerId;
} }
/** /**
* @param mixed $company * @param $stripeCustomerId
*
* @return User * @return User
*/ */
public function setCompany($company): User public function setStripeCustomerId($stripeCustomerId): User
{ {
$this->company = $company; $this->stripeCustomerId = $stripeCustomerId;
return $this; return $this;
} }
/** /**
* @return mixed * @return mixed
*/ */
public function getStripeCustomerId() public function getId()
{ {
return $this->stripeCustomerId; return $this->id;
} }
/** /**
* @param $stripeCustomerId * @param mixed $id
*
* @return User * @return User
*/ */
public function setStripeCustomerId($stripeCustomerId): User public function setId($id): User
{ {
$this->stripeCustomerId = $stripeCustomerId; $this->id = $id;
return $this; return $this;
} }
/** /**
* @return mixed * @return mixed
*/ */
public function getId() public function getSubscriptions()
{ {
return $this->id; return $this->subscriptions;
} }
/** /**
* @param mixed $id * @param mixed $subscriptions
* *
* @return User * @return User
*/ */
public function setId($id): User public function setSubscriptions($subscriptions)
{ {
$this->id = $id; $this->subscriptions = $subscriptions;
return $this; return $this;
} }
/** /**
* Returns the roles granted to the user. * Returns the roles granted to the user.
* *
...@@ -274,6 +225,25 @@ class User implements UserInterface, JsonSerializable ...@@ -274,6 +225,25 @@ class User implements UserInterface, JsonSerializable
return $this; return $this;
} }
/**
* @return mixed
*/
public function getUsername()
{
return $this->username;
}
/**
* @param mixed $username
*
* @return User
*/
public function setUsername($username): User
{
$this->username = $username;
return $this;
}
/** /**
* Specify data which should be serialized to JSON * Specify data which should be serialized to JSON
* @link https://php.net/manual/en/jsonserializable.jsonserialize.php * @link https://php.net/manual/en/jsonserializable.jsonserialize.php
...@@ -287,11 +257,10 @@ class User implements UserInterface, JsonSerializable ...@@ -287,11 +257,10 @@ class User implements UserInterface, JsonSerializable
"id" => $this->getId(), "id" => $this->getId(),
"email" => $this->getEmail(), "email" => $this->getEmail(),
"picture_url" => $this->getPicture(), "picture_url" => $this->getPicture(),
"locale" => $this->getLocale(),
"roles" => $this->getRoles(), "roles" => $this->getRoles(),
"family_name" => $this->getFamilyName(), "company_id" => $this->getCompanyId(),
"given_name" => $this->getGivenName(), "given_name" => $this->getGivenName(),
"services" => $this->getServices() "services" => $this->getSubscriptions()
]; ];
} }
} }
\ No newline at end of file
...@@ -8,6 +8,7 @@ use Symfony\Component\Security\Core\User\UserProviderInterface; ...@@ -8,6 +8,7 @@ use Symfony\Component\Security\Core\User\UserProviderInterface;
use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface; use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use HWI\Bundle\OAuthBundle\Security\Core\User\OAuthAwareUserProviderInterface; use HWI\Bundle\OAuthBundle\Security\Core\User\OAuthAwareUserProviderInterface;
use function Couchbase\defaultDecoder;
class UserProvider implements UserProviderInterface, OAuthAwareUserProviderInterface class UserProvider implements UserProviderInterface, OAuthAwareUserProviderInterface
{ {
...@@ -18,11 +19,16 @@ class UserProvider implements UserProviderInterface, OAuthAwareUserProviderInter ...@@ -18,11 +19,16 @@ class UserProvider implements UserProviderInterface, OAuthAwareUserProviderInter
// `sub` is equal to the user id in Auth0 // `sub` is equal to the user id in Auth0
const AUTH0_USER_DATA_KEY_ID = 'sub'; const AUTH0_USER_DATA_KEY_ID = 'sub';
const AUTH0_USER_APP_METADATA_KEY = 'http://konnect/metadata'; const AUTH0_USER_APP_METADATA_KEY = 'http://konnect/app_metadata';
const AUTH0_USER_APP_METADATA_KEY_COMPANY = 'company'; const AUTH0_USER_APP_METADATA_KEY_COMPANYID = 'company_id';
const AUTH0_USER_APP_METADATA_KEY_STRIPE = 'stripe_customer_id'; const AUTH0_USER_APP_METADATA_KEY_STRIPE = 'stripe_customer_id';
const AUTH0_USER_APP_METADATA_KEY_ROLES = 'roles'; const AUTH0_USER_APP_METADATA_KEY_ROLES = 'roles';
const AUTH0_USER_APP_METADATA_KEY_SUBSCRIPTIONS = 'subscriptions';
const AUTH0_USER_METADATA_KEY = 'http://konnect/user_metadata';
const AUTH0_USER_METADATA_KEY_GIVEN_NAME = 'given_name';
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -41,11 +47,12 @@ class UserProvider implements UserProviderInterface, OAuthAwareUserProviderInter ...@@ -41,11 +47,12 @@ class UserProvider implements UserProviderInterface, OAuthAwareUserProviderInter
{ {
$auth0ParsedObject = $response->getData(); $auth0ParsedObject = $response->getData();
$user = new User($auth0ParsedObject[self::AUTH0_USER_DATA_KEY_ID]); $user = new User($auth0ParsedObject[self::AUTH0_USER_DATA_KEY_ID]);
$user->setUsername($auth0ParsedObject[self::AUTH0_USER_DATA_KEY_NICKNAME]);
$user->setEmail($auth0ParsedObject[self::AUTH0_USER_DATA_KEY_EMAIL]); $user->setEmail($auth0ParsedObject[self::AUTH0_USER_DATA_KEY_EMAIL]);
$user->setGivenName(explode('@', $user->getEmail())[0]); $user->setUsername($auth0ParsedObject[self::AUTH0_USER_DATA_KEY_NICKNAME]);
$user->setGivenName($auth0ParsedObject[self::AUTH0_USER_METADATA_KEY][self::AUTH0_USER_METADATA_KEY_GIVEN_NAME] ?? $auth0ParsedObject[self::AUTH0_USER_DATA_KEY_NICKNAME]);
$user->setPicture($auth0ParsedObject[self::AUTH0_USER_DATA_KEY_PICTURE]); $user->setPicture($auth0ParsedObject[self::AUTH0_USER_DATA_KEY_PICTURE]);
$user->setCompany($auth0ParsedObject[self::AUTH0_USER_APP_METADATA_KEY][self::AUTH0_USER_APP_METADATA_KEY_COMPANY]); $user->setCompanyId($auth0ParsedObject[self::AUTH0_USER_APP_METADATA_KEY][self::AUTH0_USER_APP_METADATA_KEY_COMPANYID]);
$user->setSubscriptions($auth0ParsedObject[self::AUTH0_USER_APP_METADATA_KEY][self::AUTH0_USER_APP_METADATA_KEY_SUBSCRIPTIONS]);
$user->setStripeCustomerId($auth0ParsedObject[self::AUTH0_USER_APP_METADATA_KEY][self::AUTH0_USER_APP_METADATA_KEY_STRIPE]); $user->setStripeCustomerId($auth0ParsedObject[self::AUTH0_USER_APP_METADATA_KEY][self::AUTH0_USER_APP_METADATA_KEY_STRIPE]);
$user->addRoles($auth0ParsedObject[self::AUTH0_USER_APP_METADATA_KEY][self::AUTH0_USER_APP_METADATA_KEY_ROLES]); $user->addRoles($auth0ParsedObject[self::AUTH0_USER_APP_METADATA_KEY][self::AUTH0_USER_APP_METADATA_KEY_ROLES]);
return $user; return $user;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment