Core PHP + Okta Login Example
Played a bit with this article (also on GitHub) and Okta. I did have the same problem as mentioned here:
Fatal error: Uncaught Error: Class ‘SrcServicesOktaApiService’ not found in /your_path/index.php:10 Stack trace: #0 {main} thrown in /your_path/index.php on line 7
After playing a bit with it this is what I found out:
- Edit that index.php file mentioned in the error
- It should look a lot like this:
<?php
require('../bootstrap.php');
use SrcServicesOktaApiService;
use SrcControllersUserController;
$oktaApi = new OktaApiService;
$userController = new UserController($oktaApi);
// view data
$data = null;
[some other code here below]
- Add the two following lines after “require …”
require_once '/your_path/src/services/OktaApiService.php';
require_once '/your_path/src/controllers/UserController.php';
- Eventually it should like a lot like this:
<?php
require('../bootstrap.php');
require_once '/your_path/src/services/OktaApiService.php';
require_once '/your_path/src/controllers/UserController.php';
use SrcServicesOktaApiService;
use SrcControllersUserController;
$oktaApi = new OktaApiService;
$userController = new UserController($oktaApi);
// view data
$data = null;
[some other code here below]
At this point it should work, unless other configurations are missing
Additional steps might involve:
- Try to have the project on the root of your website, otherwise some links will not work
- Assign the php application to the current user in the Okta Admin portal
- Create the application authentication flow as described in the guide
Have fun
Thank you, just adding these two lines fixed the issue for me. I don’t know why Okta leaves this guide up without this, it does not work.
require_once ‘../src/services/OktaApiService.php’;
require_once ‘../src/controllers/UserController.php’;
Glad it helped Rob! Cheers, Fabio