1

Right now I am using laravel to fetch okta app information from the DB. I pull these rows out and the credentials differ since there are 2 different okta apps. i.e the client_secret and redirect URI's are different for each app.

Right now I pull the 2 rows out and loop through and assign credentials in the loop but the issue is that I do not know how to differentiate the apps and assign them different credentials while looping.

Boot method in service provider where I assign credentials

public function boot(OktaApp $oktaApp, Repository $repository)
{
        $oktaApps = $oktaApp
            ->where('name', 'oktaApp1')
            ->orWhere('name', 'oktaApp2')
            ->get()->toArray();
            
    foreach ($oktaApps as $app) {
        //How do I assign creds dynamically based on app name?
        $repository['services.oktaApp1'] = [
            'client_id' => $app['client_id'],
            'client_secret' => $app['client_secret'],
            'redirect' =>  $app['redirect_uri'],
            'base_url' => $app['base_url'],
        ];
    }
}

If I die and dump the results from $oktaApps

array:2 [▼
  0 => array:6 [▼
    "id" => 1
    "name" => "oktaApp1"
    "client_id" => "......removed for security....."
    "client_secret" => "......removed for security....."
    "redirect_uri" => "http://localhost:8000/login/oktaApp1/callback"
    "base_url" => "......removed for security....."
  ]
  1 => array:6 [▼
    "id" => 2
   "name" => "oktaApp2"
    "client_id" => "......removed for security....."
    "client_secret" => "......removed for security....."
    "redirect_uri" => "http://localhost:8000/login/oktaApp2/callback"
    "base_url" => "......removed for security....."
  ]
]

How I am manually assigning the values as of right now (working but hard coded)

            $repository['services.oktaApp1'] = [
                'client_id' => $app[0]['client_id'],
                'client_secret' => $app[0]['client_secret'],
                'redirect' =>  $app[0]['redirect_uri'],
                'base_url' => $app[0]['base_url'],
            ];
    
     
            $repository['services.oktaApp2'] = [
                'client_id' => $app[1]['client_id'],
                'client_secret' => $app[1]['client_secret'],
                'redirect' =>  $app[1]['redirect_uri'],
                'base_url' => $app[1]['base_url'],
            ];

1 Answer 1

3

You can make $repository['services.oktaApp1'] an array of arrays so instead you make it like so.

foreach ($oktaApps as $app) {
    $repository['services'][$app['name']] = [
        'client_id' => $app['client_id'],
        'client_secret' => $app['client_secret'],
        'redirect' =>  $app['redirect_uri'],
        'base_url' => $app['base_url'],
    ];
}

I am not sure if this will fit in your scenario so let me know.

Sign up to request clarification or add additional context in comments.

5 Comments

I will try this out right now and let you know. I just saw this and thank you for your answer.
I keep getting this error ` ``Indirect modification of overloaded element of Illuminate\Config\Repository has no effect```
Can you post the code that assign the values to the configs
I just posted the code showing how I manually assign them using an index right now. Again I want to do this in a loop to prevent hard coded values. Thank you.
I updated my answer, there was a mistake in this line $repository['services'][$app->name] =

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.