okta / okta-sdk-php

PHP SDK for the Okta API
Apache License 2.0
38 stars 71 forks source link

Resending activation emails #77

Closed LarryBarker closed 4 years ago

LarryBarker commented 4 years ago

Is it possible to resend activation emails with this SDK? We are having issues where users have not received the email, and the manager wants to send another activation email. The problem is that the code below throws an error because the user is "active" according to Okta:

$user = new \Okta\Users\User();
$foundUser = $user->get($this->okta_id);
$foundUser->activate();

I have found a work around by calling the deactivate() method before the activate() method, but this seems like an ugly way to handle this:

$user = new \Okta\Users\User();
$foundUser = $user->get($this->okta_id);
$foundUser->deactivate();
$foundUser->activate();

Any feedback is appreciated!

bretterer commented 4 years ago

@LarBearrr Thank you for your feedback and issue report here. Within the Okta API, there is a way to do this, however the method is not yet in the PHP SDK. In the future, there will be a reactivate() method for the user object.

What I can suggest is that you create a new reactivate method for you that uses the internal api calls that you can use. The method would look something like this:

public function reactivate($sendEmail = true)
    {
        $uri = "/api/v1/users/{$this->getId()}/lifecycle/reactivate";
        $uri = $this->getDataStore()->buildUri(
            $this->getDataStore()->getOrganizationUrl() . $uri
        );
        $body = $this
                ->getDataStore()
                ->executeRequest('POST', $uri, '', ['query' => ['sendEmail' => $sendEmail]]);

        return new \Okta\Users\UserActivationToken(null, $body);
    }

This is all based on the docs of https://developer.okta.com/docs/reference/api/users/#reactivate-user that would explain what API call you would need to make.

I do not have a timeline of when this method would be included directly into the SDK from our side, but it will be included in a future release.

bretterer commented 4 years ago

@LarryBarker Closing this as stale. If you are still having the issue, please feel free to re-open this ticket or create a new one with as much detail as possible. Thanks!