Closed LarryBarker closed 3 years ago
@LarBearrr Sorry about the outdated documentation we have on the repo. As an example of how to do what you are working on can be found in the integration tests at https://github.com/okta/okta-sdk-php/blob/develop/tests/Integration/UsersTest.php#L36
I will get this on our list to address.
-Brian
@bretterer No worries, thanks for the info there. Do you know if it is possible to add a user to a group with the SDK currently? If so, is there an example in the tests? You can add a user to a group through the User class with the addToGroup()
method.
Internal Ref: OKTA-291535
Lack of clear demo makes it basically unusable. Users cannot be even created without errors. How can user be created? Okta\Users\Provider does not seem to exist. Was it moved to AuthenticationProvider? If so what should be set for new users?
Hey @MattCCC I understand your frustration. If you have specific questions feel free to message me, I may be able to help.
@MattCCC @LarryBarker We are currently working on updating the PHP SDK and will take a close look at documentation.
As stated before, currently the best documentation we have is the tests. https://github.com/okta/okta-sdk-php/blob/develop/tests/Integration/UsersTest.php#L36 show successful creation of users. I know this is not the best answer, and we are aware of lack of documentation. Please stay tuned for releases of updates to the PHP SDK
Thanks @bretterer, I know it’s a large undertaking, lots of resources and endpoints and use cases to handle.
I would upvote first 1st party Laravel support 🙏 if not, something that could easily be wrapped as a Laravel package.
Thanks again!
@LarryBarker It is, but I'm on it now. We are adding every documented endpoint that is at developer.okta.com with this update. It will be a breaking change update, so a major version rev.
This update will not have 1st party laravel support, but I will bring it to the rest of the team for possible laravel package creation. Part of this update will make sure all packages are updated however, which should help implementing the SDK into your Laravel packages.
-Brian
I’m happy to write the Laravel wrapper, so long as it doesn’t require nasty composer hacks to make it work 😂
This issue has been marked stale because there has been no activity within the last 14 days. To keep this issue active, remove the stale
label.
For real. You need to update this entire SDK. It's a mess. Beyond the issues mentioned above (which I also found), the documentation is unclear on a lot of aspects of setup and config.
Below is my working example of creating a user.
But remember, this is with a bunch of fooling around to:
\Okta\Users\Profile
which is actual \Okta\Users\UserProfile
and SOOO many others)setPassword
)src
folder to rootvendor/okta
foldercomposer.json
file to correctly locate the src
file Anyway, here's the example.
header.php
<?php
require_once('../vendor/autoload.php');
$client = (new \Okta\ClientBuilder())
->setConfigFileLocation('../vendor/okta/okta.yaml')
->build();
?>
createUser.php (I took out a lot of the error handling, so it's shorter here on the HTML side)
<?php
session_start();
include '../View/header.php';
// Define variables and initialize with empty values
$username = $password = $confirm_password = $firstName = $lastName = $role = "";
$username_err = $password_err = $confirm_password_err = $firstName_err = $lastName_err = $role_err = "";
// Processing form data when form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Prepare a create POST
$user = new \Okta\Users\User();
$profile = new \Okta\Users\UserProfile();
$credentials = new \Okta\Users\UserCredentials();
$password = new \Okta\Users\PasswordCredential();
$profile->setFirstName($_POST["firstName"])
->setLastName($_POST["lastName"])
->setLogin($_POST["username"])
->setEmail($_POST["username"]);
$password->setValue($_POST["password"]);
$credentials->setPassword($password);
$user->setProfile($profile)
->setCredentials($credentials);
$createdUser = $user->create(['activate'=>'false']);
}
?>
<section id="createUser">
<h1 class="ticketHead">Create a User</h1>
<form id="myForm" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="form-group <?php echo (!empty($firstName_err)) ? 'has-error' : ''; ?>">
<label>First Name</label>
<input type="text" name="firstName" class="form-control" value="<?php echo $firstName; ?>">
<span class="help-block"><?php echo $firstName_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($lastName_err)) ? 'has-error' : ''; ?>">
<label>Last Name</label>
<input type="text" name="lastName" class="form-control" value="<?php echo $lastName; ?>">
<span class="help-block"><?php echo $lastName_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($username_err)) ? 'has-error' : ''; ?>">
<label>Email Address</label>
<input type="email" name="username" id="username" class="form-control" value="<?php echo $username; ?>">
<span class="help-block"><?php echo $username_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($password_err)) ? 'has-error' : ''; ?>">
<label>Password</label>
<input type="password" name="password" class="form-control" value="<?php echo $password; ?>">
<span class="help-block"><?php echo $password_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($confirm_password_err)) ? 'has-error' : ''; ?>">
<label>Confirm Password</label>
<input type="password" name="confirm_password" class="form-control" value="<?php echo $confirm_password; ?>">
<span class="help-block"><?php echo $confirm_password_err; ?></span>
</div>
<div class="form-group">
<input type="submit" class="button" value="Submit">
</div>
</form>
</section>
<?php include '../View/footer.php'; ?>
I have just tested the code and made a few updates with the Readme.
I am not able to figure out your creating and moving the okta.yaml information. My okta.yaml file lives at ~/.okta/php/okta.yaml
and I am able to list users for my org with the following:
try {
$client = (new \Okta\ClientBuilder())
->setConfigFileLocation('/Users/bretterer/.okta/php/okta.yaml')
->build();
} catch (\Exception $e ) {
ddd($e);
}
$users = (new \Okta\Okta)->getUsers();
ddd($users);
I also tested creating a user, and that code looks like:
try {
$client = (new \Okta\ClientBuilder())
->setConfigFileLocation('/Users/bretterer/.okta/php/okta.yaml')
->build();
} catch (\Exception $e ) {
ddd($e);
}
$user = new \Okta\Users\User();
$profile = new \Okta\Users\UserProfile();
$profile->setFirstName('John')
->setLastName('User')
->setLogin('auser@example.com')
->setEmail('auser@example.com');
$user->setProfile($profile);
$credentials = new \Okta\Users\UserCredentials();
$password = new \Okta\Users\PasswordCredential();
$password->setValue('Abcd1234!');
$recoveryQuestion = new \Okta\Users\RecoveryQuestionCredential();
$recoveryQuestion->setQuestion('What Language do I write in?')
->setAnswer('PHP!');
$provider = new \Okta\Users\AuthenticationProvider();
$provider->setName('OKTA')
->setType('OKTA');
$credentials->setPassword($password);
$credentials->setRecoveryQuestion($recoveryQuestion);
$credentials->setProvider($provider);
$user->setCredentials($credentials);
$user->create();
ddd($user);
I have updated the readme to handle these new classes. Could you explain a bit more about why you needed to move and rename files?
This will all be updated with the next PR. and can be tested with the branch update_deps
It seems that the documentation available on Packagist is out of date. Specifically, I am trying to update credentials (i.e. password) using the SDK. The current documentation says:
The
Okta\Users\Credentials
class does not actually exist. However, it appears there is aOkta\Users\UserCredentials
class. Likewise,Okta\Users\Password
does not exist, butOkta\Users\PasswordCredential
does. Also, thesetPassword
method does not exist on thePasswordCredential
class.Finally, it appears
Okta\Users\Provider
does not exist as well.Here is a working example I am using to update user profiles and passwords:
It would be helpful if the documentation/examples were updated to reflect the actual class namespaces and properties.
Any assistance is greatly appreciated.
Thank you!