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

User Management - update authentication methods #196

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
60 changes: 28 additions & 32 deletions lib/UserManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ public function getAuthorizationUrl(
];

if (isset($provider) && !\in_array($provider, $supportedProviders)) {
$msg = "Only " . implode("','", $supportedProviders) . " providers are supported";
$msg = "Only '" . implode("', '", $supportedProviders) . "' providers are supported";
throw new Exception\UnexpectedValueException($msg);
}

Expand Down Expand Up @@ -512,7 +512,6 @@ public function getAuthorizationUrl(
/**
* Authenticate a User with Password
*
* @param string $clientId This value can be obtained from the Configuration page in the WorkOS dashboard.
* @param string $email The email address of the user.
* @param string $password The password of the user.
* @param string|null $ipAddress The IP address of the request from the user who is attempting to authenticate.
Expand All @@ -522,28 +521,27 @@ public function getAuthorizationUrl(
*
* @return \WorkOS\Resource\UserResponse
*/
public function authenticateWithPassword($clientId, $email, $password, $ipAddress = null, $userAgent = null)
public function authenticateWithPassword($email, $password, $ipAddress = null, $userAgent = null)
{
$path = "users/authenticate";
$path = "user_management/authenticate";
$params = [
"client_id" => $clientId,
"grant_type" => "password",
"client_id" => WorkOS::getClientId(),
"client_secret" => WorkOS::getApiKey(),
"email" => $email,
"password" => $password,
"ip_address" => $ipAddress,
"user_agent" => $userAgent,
"grant_type" => "password",
"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 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 +550,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 +580,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 +609,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