Skip to content

Commit

Permalink
User Management - update authentication methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jbvolta committed Nov 21, 2023
1 parent d3cbb22 commit cd3b596
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 134 deletions.
43 changes: 20 additions & 23 deletions lib/UserManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ public function authenticateWithPassword($clientId, $email, $password, $ipAddres
/**
* Authenticate an OAuth or SSO User with a Code
*
* @param string $clientId This value can be obtained from the Configuration page in the WorkOS dashboard.
* @param string $code The authorization value which was passed back as a query parameter in the callback to the Redirect URI.
* @param string|null $ipAddress The IP address of the request from the user who is attempting to authenticate.
* @param string|null $userAgent The user agent of the request from the user who is attempting to authenticate.
Expand All @@ -552,27 +551,26 @@ public function authenticateWithPassword($clientId, $email, $password, $ipAddres
*
* @return \WorkOS\Resource\UserResponse
*/
public function authenticateWithCode($clientId, $code, $ipAddress = null, $userAgent = null)
public function authenticateWithCode($code, $ipAddress = null, $userAgent = null)
{
$path = "users/authenticate";
$path = "user_management/authenticate";
$params = [
"client_id" => $clientId,
"client_id" => WorkOS::getClientId(),
"client_secret" => WorkOS::getApiKey(),
"grant_type" => "authorization_code",
"code" => $code,
"ip_address" => $ipAddress,
"user_agent" => $userAgent,
"grant_type" => "authorization_code",
"client_secret" => WorkOS::getApiKey()
"user_agent" => $userAgent
];

$response = Client::request(Client::METHOD_POST, $path, null, $params, true);
$response = Client::request(Client::METHOD_POST, $path, null, $params, false);

return Resource\UserResponse::constructFromResponse($response);
}

/**
* Authenticate with Magic Auth
*
* @param string $clientId This value can be obtained from the Configuration page in the WorkOS dashboard.
* @param string $code The authorization value which was passed back as a query parameter in the callback to the Redirect URI.
* @param string $userId The unique ID of the user.
* @param string|null $ipAddress The IP address of the request from the user who is attempting to authenticate.
Expand All @@ -583,28 +581,27 @@ public function authenticateWithCode($clientId, $code, $ipAddress = null, $userA
* @return \WorkOS\Resource\UserResponse
*/

public function authenticateWithMagicAuth($clientId, $code, $userId, $ipAddress = null, $userAgent = null)
public function authenticateWithMagicAuth($code, $userId, $ipAddress = null, $userAgent = null)
{
$path = "users/authenticate";
$path = "user_management/authenticate";
$params = [
"client_id" => $clientId,
"client_id" => WorkOS::getClientId(),
"client_secret" => WorkOS::getApiKey(),
"grant_type" => "urn:workos:oauth:grant-type:magic-auth:code",
"code" => $code,
"user_id" => $userId,
"ip_address" => $ipAddress,
"user_agent" => $userAgent,
"grant_type" => "urn:workos:oauth:grant-type:magic-auth:code",
"client_secret" => WorkOS::getApiKey()
"user_agent" => $userAgent
];

$response = Client::request(Client::METHOD_POST, $path, null, $params, true);
$response = Client::request(Client::METHOD_POST, $path, null, $params, false);

return Resource\UserResponse::constructFromResponse($response);
}

/**
* Authenticate with TOTP
*
* @param string $clientId This value can be obtained from the Configuration page in the WorkOS dashboard.
* @param string $pendingAuthenticationToken
* @param string $authenticationChallengeId
* @param string $code
Expand All @@ -613,19 +610,19 @@ public function authenticateWithMagicAuth($clientId, $code, $userId, $ipAddress
*
* @return \WorkOS\Resource\UserResponse
*/
public function authenticateWithTotp($clientId, $pendingAuthenticationToken, $authenticationChallengeId, $code)
public function authenticateWithTotp($pendingAuthenticationToken, $authenticationChallengeId, $code)
{
$path = "users/authenticate";
$path = "user_management/authenticate";
$params = [
"client_id" => $clientId,
"client_id" => WorkOS::getClientId(),
"client_secret" => WorkOS::getApiKey(),
"grant_type" => "urn:workos:oauth:grant-type:mfa-totp",
"pending_authentication_token" => $pendingAuthenticationToken,
"authentication_challenge_id" => $authenticationChallengeId,
"code" => $code,
"grant_type" => "urn:workos:oauth:grant-type:mfa-totp",
"client_secret" => WorkOS::getApiKey()
];

$response = Client::request(Client::METHOD_POST, $path, null, $params, true);
$response = Client::request(Client::METHOD_POST, $path, null, $params, false);

return Resource\UserResponse::constructFromResponse($response);
}
Expand Down
Loading

0 comments on commit cd3b596

Please sign in to comment.