diff --git a/app/config/errors.php b/app/config/errors.php index 77c132f0f..44e8401e6 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -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 the docs 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 the docs 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.', diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 5fad398d1..69602dc42 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -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', []); diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 3dfb02ff6..d45e36904 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -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';