{"id":19745163,"url":"https://github.com/castle/castle-php","last_synced_at":"2025-04-30T07:33:54.011Z","repository":{"id":10662603,"uuid":"12895656","full_name":"castle/castle-php","owner":"castle","description":"PHP library for Castle","archived":false,"fork":false,"pushed_at":"2023-03-31T08:17:18.000Z","size":791,"stargazers_count":8,"open_issues_count":3,"forks_count":8,"subscribers_count":21,"default_branch":"develop","last_synced_at":"2024-09-19T11:43:51.906Z","etag":null,"topics":["castle","fraud-detection","fraud-prevention","php","sdk"],"latest_commit_sha":null,"homepage":"https://castle.io","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/castle.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-09-17T13:17:57.000Z","updated_at":"2024-04-08T00:31:28.000Z","dependencies_parsed_at":"2024-06-19T04:11:22.640Z","dependency_job_id":"e37c572d-034f-4017-9691-78a37b07d68f","html_url":"https://github.com/castle/castle-php","commit_stats":{"total_commits":266,"total_committers":12,"mean_commits":"22.166666666666668","dds":0.2857142857142857,"last_synced_commit":"f9125e23d8836d40ab9fc67424d4b7e838337b52"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/castle%2Fcastle-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/castle%2Fcastle-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/castle%2Fcastle-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/castle%2Fcastle-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/castle","download_url":"https://codeload.github.com/castle/castle-php/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224202878,"owners_count":17272807,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["castle","fraud-detection","fraud-prevention","php","sdk"],"created_at":"2024-11-12T02:04:29.286Z","updated_at":"2024-11-12T02:04:29.948Z","avatar_url":"https://github.com/castle.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest Stable Version](https://poser.pugx.org/castle/castle-php/v/stable.svg)](https://packagist.org/packages/castle/castle-php) [![Total Downloads](https://poser.pugx.org/castle/castle-php/downloads.svg)](https://packagist.org/packages/castle/castle-php) [![License](https://poser.pugx.org/castle/castle-php/license.svg)](https://packagist.org/packages/castle/castle-php)\n\n[![Code Climate](https://codeclimate.com/github/castle/castle-php.png)](https://codeclimate.com/github/castle/castle-php)\n[![Coverage Status](https://coveralls.io/repos/github/castle/castle-php/badge.svg?branch=fix%2Fcode-coverage)](https://coveralls.io/github/castle/castle-php?branch=fix%2Fcode-coverage)\n\n# PHP SDK for Castle\n\n**[Castle](https://castle.io) analyzes user behavior in web and mobile apps to stop fraud before it happens.**\n\n\n## Usage\n\nSee the [documentation](https://docs.castle.io) for how to use this SDK with the Castle APIs\n\n## Getting started\n\nObtain the latest version of the Castle PHP bindings with:\n\n```bash\ngit clone --single-branch --branch master https://github.com/castle/castle-php\n```\n\nTo get started, add the following to your PHP script:\n\n```php\nrequire_once(\"/path/to/castle-php/lib/Castle.php\");\n```\n\nConfigure the library with your Castle API secret.\n\n```php\nCastle::setApiKey('YOUR_API_SECRET');\n```\n\n## Optional Configurations\n\nSet preferred connection and request timeouts:\nvalid options for setting are:\n- `CURLOPT_CONNECTTIMEOUT`\n- `CURLOPT_CONNECTTIMEOUT_MS`\n- `CURLOPT_TIMEOUT`\n- `CURLOPT_TIMEOUT_MS`\n\n```php\nCastle::setCurlOpts($curlOpts)\n```\n\nSet a specified list of request headers to include with event context (optional, not recommended):\n```php\nCastle::setUseAllowlist($headers)\n```\n\n## Request context\n\nBy default, Castle extracts all the necessary information, such as IP and request\nheaders, from the PHP globals in order to build and send the requests to the\nCastle API. However in some cases you want to track data to Castle from a context\nwhere these globals are not available, eg. when tracking async in a background\nworker. In this case you can build the request context manually.\n\n### Origin IP Address\nBy default, the SDK extracts the contextual client IP address from headers in the following priority:\n1. `X-Forwarded-For`\n2. `X-Real-Ip`\n3. `REMOTE_ADDR`\n\nIf the true client IP address is not specified in the above headers, you can manually set the IP address like so:\n\n```php\nCastle_RequestContext['ip'] = '1.1.1.1'\n$context = Castle_RequestContext::extractJson();\n```\n\n## Errors\nWhenever something unexpected happens, an [exception](/lib/Castle/Errors.php) is thrown to indicate what went wrong.\n\n| Name                             | Description     |\n|:---------------------------------|:----------------|\n| `Castle_Error`                  | A generic error |\n| `Castle_RequestError`           | A request failed. Probably due to a network error |\n| `Castle_ApiError`               | An unexpected error for the Castle API |\n| `Castle_ConfigurationError`     | The Castle secret API key has not been set |\n| `Castle_UnauthorizedError`      | Wrong Castle API secret key |\n| `Castle_BadRequest`             | The request was invalid. For example if a challenge is created without the user having MFA enabled. |\n| `Castle_ForbiddenError`         | The user has entered the wrong code too many times and a new challenge has to be requested. |\n| `Castle_NotFoundError`          | The resource requestd was not found. For example if a session has been revoked. |\n| `Castle_InvalidParametersError` | One or more of the supplied parameters are incorrect. Check the response for more information. |\n| `Castle_InvalidRequestTokenError` | The request token parameter is missing or invalid |\n\n## Running test suite\nExecute `vendor/bin/phpunit test` to run the full test suite\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcastle%2Fcastle-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcastle%2Fcastle-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcastle%2Fcastle-php/lists"}