Skip to content

Commit

Permalink
added user password change
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalyan Halder committed Mar 22, 2022
1 parent 4cbd3f2 commit 366b3e3
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 2 deletions.
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ here `id` and `username` is mendatory. You can provide following field to update
| country | string |Update `country` |


>4. Delete single/bulk IDP User
## 4. Delete single/bulk IDP User

_provide user `single id` to delete single user or provide `array of user id` to delete bulk user from `IDP`_

```
$userID = 'ID';
Expand All @@ -153,10 +155,38 @@ here `id` and `username` is mendatory. You can provide following field to update
->get();
```
here - `$userID` can be single user ID or array of user ID.
*here - `$userID` can be single user ID or array of user ID.*

## 5. Reset password of users
> user api, do not need admin permission
_as a param pass a array of user crediantials like following example -_

```
$response = IdpUser()->setPayload([
'current_password' => 'kalyan111',
'username' => '01521212121',
'new_password' => 'newPass'
])->userResetPassword()->get();
```



## 5. find user list
> query users from IDP
_as a param pass a array of filter like following example -_

```
$response = IdpUser()->setPayload([
'page' => 1,
'count' => 10,
'filter' => ''
])->findUsers()->get();
```


## Adding new Gateway

Expand Down
11 changes: 11 additions & 0 deletions src/Idps/Wso2idp.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ public function update(array $userInformation)
return $this;
}

/**
* /me endpoint
* this endpoint to update password
*/
public function userResetPassword($userCrediantialInfo)
{
$AT = new Wso2IdpUsers($this->settings->base_url, $this->settings->username, $this->settings->password, $this->settings->idp_log );
$this->response = $AT->userResetPassword($userCrediantialInfo);
return $this;
}


public function delete( $userInformation = null)
{
Expand Down
39 changes: 39 additions & 0 deletions src/SDK/Wso2Idp/IdpGlobal.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ public function isEnabledDebug(){
public function endpointUserInfo($userID){
return $this->apiUrl . '/scim2/Users/'.$userID;
}

public function endpointUserCreate(){
return $this->apiUrl . '/scim2/Users';
}

public function endpointUserUpdate($userID){
return $this->apiUrl . '/scim2/Users/' . $userID;
}

public function endpointUserPasswordReset(){
return $this->apiUrl . '/scim2/Me';
}

public function endpointUserFiltering($args){
$pageNo = $args['page'] ?? 1;
$countPerPage = $args['count'] ?? 10;
Expand Down Expand Up @@ -113,6 +119,10 @@ public function prepareResponse(Response $response, array $data = [], $customMes
]);
}

if(!empty($customMessage)){
$message = $customMessage;
}

if(empty($data) && !empty($response->json())){
$responseData = $response->json();
} else if(!empty($data) && !empty($response->json())){
Expand Down Expand Up @@ -200,6 +210,35 @@ public function prepareUserInfoToBeCreated($userinfo)
return $payload;
}

public function preparePasswordResetSchema($userCrediantialInfo)
{
$currentPassword = $userCrediantialInfo['current_password'] ?? null;
$username = $userCrediantialInfo['username'] ?? null;
$newPassword = $userCrediantialInfo['new_password'] ?? null;


if(empty($currentPassword) || empty($username) || empty($newPassword)){
$this->logInfo("missing necessary user crediantial. Provided user crediantial - ", (array) $userCrediantialInfo);
throw new \Exception("username or password or new password missing", 422);
}

$payload = [
'schemas' => [
"urn:ietf:params:scim:api:messages:2.0:PatchOp"
],
'Operations' => [
[
"op" => "add",
"value" => [
"password" => $newPassword
]
]
]
];

return $payload;
}

public function prepareUserInfoToBeUpdated($userinfo)
{
$ID = $userinfo['id'] ?? null;
Expand Down
21 changes: 21 additions & 0 deletions src/SDK/Wso2Idp/Wso2IdpUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ public function userInfo($userID){
}
}

public function userResetPassword($userCrediantialInfo){
try {
$payload = $this->preparePasswordResetSchema($userCrediantialInfo);
$this->logInfo("payload", $payload);
$response = Http::withBasicAuth($userCrediantialInfo['username'], $userCrediantialInfo['current_password'])
->withHeaders([
'Content-Type' => 'application/json'
])
->withOptions([
'verify' => false
])
->patch($this->endpointUserPasswordReset(), $payload);
} catch (\Exception $exception){
$exceptionInfo = $this->response($exception->getMessage(), $userCrediantialInfo, $exception->getCode(), false);
$this->logInfo($exception->getMessage(), $exceptionInfo);

return $exceptionInfo;
}
return $this->prepareResponse($response, $userCrediantialInfo, ($response->status() == 401 ? "Username or password is incorrect. Please try with correct username or password." : null));
}

public function findUsers($filter){
try {
if(empty($filter)){
Expand Down

0 comments on commit 366b3e3

Please sign in to comment.