1
0
Fork 0
mirror of synced 2024-06-17 10:14:50 +12:00

feat: move oauth errors to projects

This commit is contained in:
Christy Jacob 2022-02-09 01:25:52 +04:00
parent 661630c1c6
commit 0833662606
3 changed files with 45 additions and 49 deletions

View file

@ -141,33 +141,6 @@ return [
'code' => 501,
],
/** OAuth Errors */
Exception::OAUTH_PROVIDER_DISABLED => [
'name' => Exception::OAUTH_PROVIDER_DISABLED,
'description' => 'The chosen OAuth provider is disabled. Please contact your project administrator for more information.',
'code' => 412,
],
Exception::OAUTH_PROVIDER_UNSUPPORTED => [
'name' => Exception::OAUTH_PROVIDER_UNSUPPORTED,
'description' => 'The chosen OAuth provider is unsupported. Please check <a href="/docs/client/account?sdk=web-default#accountCreateOAuth2Session"> the docs</a> for the complete list of supported OAuth providers.',
'code' => 501,
],
Exception::OAUTH_INVALID_SUCCESS_URL => [
'name' => Exception::OAUTH_INVALID_SUCCESS_URL,
'description' => 'Invalid URL received for OAuth success redirect.',
'code' => 400,
],
Exception::OAUTH_INVALID_FAILURE_URL => [
'name' => Exception::OAUTH_INVALID_FAILURE_URL,
'description' => 'Invalid URL received for OAuth failure redirect.',
'code' => 400,
],
Exception::OAUTH_MISSING_USER_ID => [
'name' => Exception::OAUTH_MISSING_USER_ID,
'description' => 'Failed to obtain user ID from the OAuth provider.',
'code' => 400,
],
/** Teams */
Exception::TEAM_NOT_FOUND => [
'name' => Exception::TEAM_NOT_FOUND,
@ -409,6 +382,31 @@ return [
'description' => 'The project ID is either missing or not valid. Please check the value of the X-Appwrite-Project header to ensure the correct project ID is being used.',
'code' => 400,
],
Exception::PROJECT_PROVIDER_DISABLED => [
'name' => Exception::PROJECT_PROVIDER_DISABLED,
'description' => 'The chosen OAuth provider is disabled. Please contact your project administrator for more information.',
'code' => 412,
],
Exception::PROJECT_PROVIDER_UNSUPPORTED => [
'name' => Exception::PROJECT_PROVIDER_UNSUPPORTED,
'description' => 'The chosen OAuth provider is unsupported. Please check <a href="/docs/client/account?sdk=web-default#accountCreateOAuth2Session"> the docs</a> for the complete list of supported OAuth providers.',
'code' => 501,
],
Exception::PROJECT_INVALID_SUCCESS_URL => [
'name' => Exception::PROJECT_INVALID_SUCCESS_URL,
'description' => 'Invalid URL received for OAuth success redirect.',
'code' => 400,
],
Exception::PROJECT_INVALID_FAILURE_URL => [
'name' => Exception::PROJECT_INVALID_FAILURE_URL,
'description' => 'Invalid URL received for OAuth failure redirect.',
'code' => 400,
],
Exception::PROJECT_MISSING_USER_ID => [
'name' => Exception::PROJECT_MISSING_USER_ID,
'description' => 'Failed to obtain user ID from the OAuth provider.',
'code' => 400,
],
Exception::WEBHOOK_NOT_FOUND => [
'name' => Exception::WEBHOOK_NOT_FOUND,
'description' => 'Webhook with the requested ID could not be found.',

View file

@ -283,13 +283,13 @@ App::get('/v1/account/sessions/oauth2/:provider')
}
if (empty($appId) || empty($appSecret)) {
throw new Exception('This provider is disabled. Please configure the provider app ID and app secret key from your ' . APP_NAME . ' console to continue.', 412, Exception::OAUTH_PROVIDER_DISABLED);
throw new Exception('This provider is disabled. Please configure the provider app ID and app secret key from your ' . APP_NAME . ' console to continue.', 412, Exception::PROJECT_PROVIDER_DISABLED);
}
$className = 'Appwrite\\Auth\\OAuth2\\'.\ucfirst($provider);
if (!\class_exists($className)) {
throw new Exception('Provider is not supported', 501, Exception::OAUTH_PROVIDER_UNSUPPORTED);
throw new Exception('Provider is not supported', 501, Exception::PROJECT_PROVIDER_UNSUPPORTED);
}
if(empty($success)) {
@ -407,7 +407,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
$className = 'Appwrite\\Auth\\OAuth2\\' . \ucfirst($provider);
if (!\class_exists($className)) {
throw new Exception('Provider is not supported', 501, Exception::OAUTH_PROVIDER_UNSUPPORTED);
throw new Exception('Provider is not supported', 501, Exception::PROJECT_PROVIDER_UNSUPPORTED);
}
$oauth2 = new $className($appId, $appSecret, $callback);
@ -423,11 +423,11 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
}
if (!$validateURL->isValid($state['success'])) {
throw new Exception('Invalid redirect URL for success login', 400, Exception::OAUTH_INVALID_SUCCESS_URL);
throw new Exception('Invalid redirect URL for success login', 400, Exception::PROJECT_INVALID_SUCCESS_URL);
}
if (!empty($state['failure']) && !$validateURL->isValid($state['failure'])) {
throw new Exception('Invalid redirect URL for failure login', 400, Exception::OAUTH_INVALID_FAILURE_URL);
throw new Exception('Invalid redirect URL for failure login', 400, Exception::PROJECT_INVALID_FAILURE_URL);
}
$state['failure'] = null;
@ -451,7 +451,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
$response->redirect($state['failure'], 301, 0);
}
throw new Exception('Missing ID from OAuth2 provider', 400, Exception::OAUTH_MISSING_USER_ID);
throw new Exception('Missing ID from OAuth2 provider', 400, Exception::PROJECT_MISSING_USER_ID);
}
$sessions = $user->getAttribute('sessions', []);

View file

@ -34,15 +34,15 @@ class Exception extends \Exception
*/
/** General */
const GENERAL_UNKNOWN = 'unknown';
const GENERAL_ACCESS_FORBIDDEN = 'access_forbidden';
const GENERAL_UNKNOWN_ORIGIN = 'unknown_origin';
const GENERAL_SERVICE_DISABLED = 'service_disabled';
const GENERAL_UNAUTHORIZED_SCOPE = 'unauthorized_scope';
const GENERAL_RATE_LIMIT_EXCEEDED = 'rate_limit_exceeded';
const GENERAL_SMTP_DISABLED = 'smtp_disabled';
const GENERAL_ARGUMENT_INVALID = 'argument_invalid';
const GENERAL_SERVER_ERROR = 'server_error';
const GENERAL_UNKNOWN = 'general_unknown';
const GENERAL_ACCESS_FORBIDDEN = 'general_access_forbidden';
const GENERAL_UNKNOWN_ORIGIN = 'general_unknown_origin';
const GENERAL_SERVICE_DISABLED = 'general_service_disabled';
const GENERAL_UNAUTHORIZED_SCOPE = 'general_unauthorized_scope';
const GENERAL_RATE_LIMIT_EXCEEDED = 'general_rate_limit_exceeded';
const GENERAL_SMTP_DISABLED = 'general_smtp_disabled';
const GENERAL_ARGUMENT_INVALID = 'general_argument_invalid';
const GENERAL_SERVER_ERROR = 'general_server_error';
/** Users */
const USER_COUNT_EXCEEDED = 'user_count_exceeded';
@ -63,13 +63,6 @@ class Exception extends \Exception
const USER_UNAUTHORIZED = 'user_unauthorized';
const USER_AUTH_METHOD_UNSUPPORTED = 'user_auth_method_unsupported';
/** OAuth **/
const OAUTH_PROVIDER_DISABLED = 'oauth_provider_disabled';
const OAUTH_PROVIDER_UNSUPPORTED = 'oauth_provider_unsupported';
const OAUTH_INVALID_SUCCESS_URL = 'oauth_invalid_success_url';
const OAUTH_INVALID_FAILURE_URL = 'oauth_invalid_failure_url';
const OAUTH_MISSING_USER_ID = 'oauth_missing_user_id';
/** Teams */
const TEAM_NOT_FOUND = 'team_not_found';
const TEAM_INVITE_ALREADY_EXISTS = 'team_invite_already_exists';
@ -138,6 +131,11 @@ class Exception extends \Exception
/** Projects */
const PROJECT_NOT_FOUND = 'project_not_found';
const PROJECT_UNKNOWN = 'project_unknown';
const PROJECT_PROVIDER_DISABLED = 'project_provider_disabled';
const PROJECT_PROVIDER_UNSUPPORTED = 'project_provider_unsupported';
const PROJECT_INVALID_SUCCESS_URL = 'project_invalid_success_url';
const PROJECT_INVALID_FAILURE_URL = 'project_invalid_failure_url';
const PROJECT_MISSING_USER_ID = 'project_missing_user_id';
/** Webhooks */
const WEBHOOK_NOT_FOUND = 'webhook_not_found';