public function Auth0::__construct in Auth0 Single Sign On 8.2
BaseAuth0 Constructor.
Parameters
array $config - Required configuration options.: Configuration:
- domain (String) Required. Auth0 domain for your tenant
- client_id (String) Required. Client ID found in the Application settings
- client_secret (String) Required. Client Secret found in the Application settings
- redirect_uri (String) Required. Authentication callback URI
- response_mode (String) Optional. Default `query`
- response_type (String) Optional. Default `code`
- persist_user (Boolean) Optional. Persist the user info, default true
- persist_access_token (Boolean) Optional. Persist the access token, default false
- persist_refresh_token (Boolean) Optional. Persist the refresh token, default false
- persist_id_token (Boolean) Optional. Persist the ID token, default false
- store (Mixed) Optional. A class that implements StorageInterface or false for none; leave empty to default to SessionStore
- state_handler (Mixed) Optional. A class that implements StateHandler of false for none; leave empty to default to SessionStore SessionStateHandler
- debug (Boolean) Optional. Turn on debug mode, default false
- guzzle_options (Object) Optional. Options passed to Guzzle
- skip_userinfo (Boolean) Optional. True to use id_token for user, false to call the userinfo endpoint, default false
- session_base_name (String) Optional. A common prefix for all session keys. Default `auth0_`
- session_cookie_expires (Integer) Optional. Seconds for session cookie to expire (if default store is used). Default `604800`
Throws
CoreException If `domain` is not provided.
CoreException If `client_id` is not provided.
CoreException If `client_secret` is not provided.
CoreException If `redirect_uri` is not provided.
File
- vendor/
auth0/ auth0-php/ src/ Auth0.php, line 260
Class
- Auth0
- Class Auth0 Provides access to Auth0 authentication functionality.
Namespace
Auth0\SDKCode
public function __construct(array $config) {
if (empty($config['domain'])) {
throw new CoreException('Invalid domain');
}
if (empty($config['client_id'])) {
throw new CoreException('Invalid client_id');
}
if (empty($config['client_secret'])) {
throw new CoreException('Invalid client_secret');
}
if (empty($config['redirect_uri'])) {
throw new CoreException('Invalid redirect_uri');
}
$this->domain = $config['domain'];
$this->clientId = $config['client_id'];
$this->clientSecret = $config['client_secret'];
$this->clientSecretEncoded = !empty($config['secret_base64_encoded']);
$this->redirectUri = $config['redirect_uri'];
if (isset($config['audience'])) {
$this->audience = $config['audience'];
}
if (isset($config['response_mode'])) {
$this->responseMode = $config['response_mode'];
}
if (isset($config['response_type'])) {
$this->responseType = $config['response_type'];
}
if (isset($config['scope'])) {
$this->scope = $config['scope'];
}
if (isset($config['guzzle_options'])) {
$this->guzzleOptions = $config['guzzle_options'];
}
$this->skipUserinfo = false;
if (isset($config['skip_userinfo']) && is_bool($config['skip_userinfo'])) {
$this->skipUserinfo = $config['skip_userinfo'];
}
// If a token algorithm is passed, make sure it's a specific string.
if (!empty($config['id_token_alg'])) {
if (!in_array($config['id_token_alg'], [
'HS256',
'RS256',
])) {
throw new CoreException('Invalid id_token_alg; must be "HS256" or "RS256"');
}
$this->idTokenAlg = $config['id_token_alg'];
}
// If a token audience is passed, make sure it's an array.
if (!empty($config['id_token_aud'])) {
if (!is_array($config['id_token_aud'])) {
throw new CoreException('Invalid id_token_aud; must be an array of string values');
}
$this->idTokenAud = $config['id_token_aud'];
}
// If a token issuer is passed, make sure it's an array.
if (!empty($config['id_token_iss'])) {
if (!is_array($config['id_token_iss'])) {
throw new CoreException('Invalid id_token_iss; must be an array of string values');
}
$this->idTokenIss = $config['id_token_iss'];
}
$this->debugMode = isset($config['debug']) ? $config['debug'] : false;
// User info is persisted by default.
if (isset($config['persist_user']) && false === $config['persist_user']) {
$this
->dontPersist('user');
}
// Access token is not persisted by default.
if (!isset($config['persist_access_token']) || false === $config['persist_access_token']) {
$this
->dontPersist('access_token');
}
// Refresh token is not persisted by default.
if (!isset($config['persist_refresh_token']) || false === $config['persist_refresh_token']) {
$this
->dontPersist('refresh_token');
}
// ID token is not persisted by default.
if (!isset($config['persist_id_token']) || false === $config['persist_id_token']) {
$this
->dontPersist('id_token');
}
$session_base_name = !empty($config['session_base_name']) ? $config['session_base_name'] : SessionStore::BASE_NAME;
$session_cookie_expires = isset($config['session_cookie_expires']) ? $config['session_cookie_expires'] : SessionStore::COOKIE_EXPIRES;
if (isset($config['store'])) {
if ($config['store'] === false) {
$emptyStore = new EmptyStore();
$this
->setStore($emptyStore);
}
else {
$this
->setStore($config['store']);
}
}
else {
$sessionStore = new SessionStore($session_base_name, $session_cookie_expires);
$this
->setStore($sessionStore);
}
if (isset($config['state_handler'])) {
if ($config['state_handler'] === false) {
$this->stateHandler = new DummyStateHandler();
}
else {
$this->stateHandler = $config['state_handler'];
}
}
else {
$stateStore = new SessionStore($session_base_name, $session_cookie_expires);
$this->stateHandler = new SessionStateHandler($stateStore);
}
$this->authentication = new Authentication($this->domain, $this->clientId, $this->clientSecret, $this->audience, $this->scope, $this->guzzleOptions);
$this->user = $this->store
->get('user');
$this->accessToken = $this->store
->get('access_token');
$this->idToken = $this->store
->get('id_token');
$this->refreshToken = $this->store
->get('refresh_token');
}