# Reading auth0 credentials from db on laravel project

**URL:** <https://community.auth0.com/t/reading-auth0-credentials-from-db-on-laravel-project/84902>\
**Category:** Get Help\
**Tags:** laravel, login, auth0\
**Created:** [June 9, 2022, 8:08pm UTC](https://community.auth0.com/t/reading-auth0-credentials-from-db-on-laravel-project/84902 "2022-06-09T20:08:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![leandro](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/leandro/32/38672_2.png) [@leandro](https://community.auth0.com/u/leandro)\
**Post date:** [June 9, 2022, 8:08pm UTC](https://community.auth0.com/t/reading-auth0-credentials-from-db-on-laravel-project/84902/1 "2022-06-09T20:08:38Z")

</div>

Hi guys my app is working nice but now I need to read auth0 credentials from db instead of config/auth0.php file?  
To provide more details:  
Im buildding a multitenant application.  
Tenant should use different auth0 credentials.  
Tenant is identified based on requested url.

Does the sdk natively support this feature ?  
I tryed modfing the auth0.php file to read values directly from database but laravel throws an exception informing that db connection is not ready at this time.

Any ideas ?

---

<div class="post-metadata">

**Author:** ![evansims](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/evansims/32/27011_2.png) [@evansims](https://community.auth0.com/u/evansims)\
**Post date:** [June 10, 2022, 2:22am UTC](https://community.auth0.com/t/reading-auth0-credentials-from-db-on-laravel-project/84902/2 "2022-06-10T02:22:42Z")

</div>

Hi there!

We don’t have any built-in support for doing that for you. I would suggest handling pulling the configuration details you need from your database within your own application logic, and updating the SDK’s configuration dynamically as needed.

```php
// Specific changes:
app('auth0')->getConfiguration()->setCustomDomain('an.example.com');

```

```php
// Overwriting the configuration completely:
$yourConfiguration = new \Auth0\SDK\Configuration\SdkConfiguration([
   'your' => 'settings'
]);

app('auth0')->setConfiguration($yourConfiguration);

```

You can reference the `SdkConfiguration` options available from [the underlying PHP SDK](https://github.com/auth0/auth0-PHP#configuration-options).

---

<div class="post-metadata">

**Author:** ![leandro](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/leandro/32/38672_2.png) [@leandro](https://community.auth0.com/u/leandro)\
**Post date:** [June 10, 2022, 7:19pm UTC](https://community.auth0.com/t/reading-auth0-credentials-from-db-on-laravel-project/84902/3 "2022-06-10T19:19:48Z")

</div>

Thanks !!!  
I understand that basically I will need to find out where is the sdk initialized to bring the config array from db.

Leandro.

---

<div class="post-metadata">

**Author:** ![leandro](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/leandro/32/38672_2.png) [@leandro](https://community.auth0.com/u/leandro)\
**Post date:** [June 13, 2022, 4:21pm UTC](https://community.auth0.com/t/reading-auth0-credentials-from-db-on-laravel-project/84902/4 "2022-06-13T16:21:31Z")

</div>

> [@evansims](#):
>
> ```auto
> app('auth0')->getConfiguration()->setCustomDomain('an.example.com');
> 
> ```
> 
> ```auto
> 
> ```

Ok this is what i didi:  
in the class definition at (vendor/auth0/login/src/Auth0.php)  
I modified the get sdk method like:

```auto
    public function getSdk(): \Auth0\SDK\Auth0
    {
        if ($this->sdk === null) {
            $this->sdk = new \Auth0\SDK\Auth0([

                'strategy' => env('AUTH0_STRATEGY', 'webapp'),
                'customDomain' => env('AUTH0_CUSTOM_DOMAIN'),
                'domain' => \App\Helpers\ClassAuth0Creds::get_AUTH0_KEY('AUTH0_DOMAIN'),
                'clientId' => \App\Helpers\ClassAuth0Creds::get_AUTH0_KEY('AUTH0_CLIENT_ID'),
                'redirectUri' => \App\Helpers\ClassAuth0Creds::get_AUTH0_KEY('AUTH0_REDIRECT_URI'),
                'clientSecret' => \App\Helpers\ClassAuth0Creds::get_AUTH0_KEY('AUTH0_CLIENT_SECRET'),
                'audience' => \Auth0\Laravel\Configuration::stringToArrayOrNull(env('AUTH0_AUDIENCE')),
                'scope' => \Auth0\Laravel\Configuration::stringToArrayOrNull(env('AUTH0_SCOPE')),
                'organization' => \Auth0\Laravel\Configuration::stringToArrayOrNull(env('AUTH0_ORGANIZATION')),
                'cookieSecret' => env('AUTH0_COOKIE_SECRET', env('APP_KEY')),
                'cookieExpires' => env('COOKIE_EXPIRES', 0),
                'cookieDomain' => env('AUTH0_COOKIE_DOMAIN'),
                'cookiePath' => env('AUTH0_COOKIE_PATH'),
                'cookieSecure' => \Auth0\Laravel\Configuration::stringToBoolOrNull(env('AUTH0_COOKIE_SECURE'), false),
                'routes' => [
                    'home' => env('AUTH0_ROUTE_HOME', '/'),
                    'login' => env('AUTH0_ROUTE_LOGIN', 'login')
                ]

            ]);

            $this->setSdkTelemetry();
        }

        return $this->sdk;
    }

```

then , the:

```auto
 \App\Helpers\ClassAuth0Creds

```

Is where I read the credentials on the db.  
Perhaps it is not the most elegant solution but it works.  
Any suggestion is wellcome.  
thanks.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 28, 2022, 12:26pm UTC](https://community.auth0.com/t/reading-auth0-credentials-from-db-on-laravel-project/84902/5 "2022-07-28T12:26:40Z")

</div>


