Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added admin user creation feature #39

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ before running them.
Version History
---------------

0.2.11 (06/01/2020)
0.2.11 (28/02/2020)

Added method to get a user by an access token - bjoernHeneka
* Added method to create a user group - [abhi36](https://github.com/abhi36)

0.2.11 (22/02/2020)

* Added method to create a user by admin and set the status to CONFIRMED - [abhi36](https://github.com/abhi36)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove these changes? if this PR is merged, I'll need to update the date and version anyway so I'll add make these changes myself.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes are still here in the diff.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a reminder about this one.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is still here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated it after interactive rebase to my branch. Not sure how it's still not getting updated. Those lines are even not showing in my codebase now

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it's on this commit 745e545

0.2.10 (21/10/2019)

Expand Down
98 changes: 97 additions & 1 deletion src/CognitoClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public function getUser($username)
'UserPoolId' => $this->userPoolId,
]);
return $response;
} catch (Exception $e) {
} catch (CognitoIdentityProviderException $e) {
throw CognitoResponseException::createFromCognitoException($e);
}
}
Expand All @@ -259,6 +259,85 @@ public function deleteUser($accessToken)
}
}


/**
* Disable a user
* @param string $username
*/
public function adminEnableUser($username){
try {
$this->client->adminEnableUser([
pmill marked this conversation as resolved.
Show resolved Hide resolved
'UserPoolId' => $this->userPoolId,
'Username' => $username
]);
} catch (CognitoIdentityProviderException $e) {
throw CognitoResponseException::createFromCognitoException($e);
}
}

/**
* Disable a user
* @param string $username
*/
public function adminDisableUser($username){
try {
$this->client->adminDisableUser([
pmill marked this conversation as resolved.
Show resolved Hide resolved
'UserPoolId' => $this->userPoolId,
'Username' => $username
]);
} catch (CognitoIdentityProviderException $e) {
throw CognitoResponseException::createFromCognitoException($e);
}
}

/**
* @param string $username
* @param string $password
* @param array $userAttributes
* @param boolean $confirmSignup
* @return object
* @throws Exception
*/
public function adminCreateUser($username, $password, $attributes = [])
{
$userAttributes = $this->buildAttributesArray($attributes);
try {
$registeredUser = $this->client->adminCreateUser([
'UserPoolId' => $this->userPoolId,
'Username' => $username,
'TemporaryPassword' => $password,
'UserAttributes' => $userAttributes,
'MessageAction' => "SUPPRESS",
'DesiredDeliveryMediums' => ["EMAIL"]
]);

return $registeredUser;
} catch (CognitoIdentityProviderException $e) {
throw CognitoResponseException::createFromCognitoException($e);
}
}


/**
* Set a admin added user as CONFIRMED. It sets the parameter password as final
* @param string $username
* @param string $password
* @return object
* @throws Exception
*/
public function adminConfirmAddedUser($username, $password){
pmill marked this conversation as resolved.
Show resolved Hide resolved
$respAuthenticate = [];
try {
$respAuthenticate = $this->authenticate($username, $password);
} catch (ChallengeException $e) {
if ($e->getChallengeName() === self::CHALLENGE_NEW_PASSWORD_REQUIRED) {
$respAuthenticate = $this->respondToNewPasswordRequiredChallenge($username, $password, $e->getSession());
}
}
return $respAuthenticate;
}


/**
* @param string $username
* @throws Exception
Expand Down Expand Up @@ -294,6 +373,23 @@ public function addUserToGroup($username, $groupName)
}
}

/**
* Create a group for users
* @param string $username
* @param string $groupName
* @throws Exception
*/
public function createUserGroup($groupName){
pmill marked this conversation as resolved.
Show resolved Hide resolved
try{
pmill marked this conversation as resolved.
Show resolved Hide resolved
$this->client->createGroup([
pmill marked this conversation as resolved.
Show resolved Hide resolved
"GroupName" => $groupName,
"UserPoolId" => $this->userPoolId
]);
} catch (CognitoIdentityProviderException $e) {
throw CognitoResponseException::createFromCognitoException($e);
}
}

/**
* @param $username
* @param array $attributes
Expand Down