{"id":19645753,"url":"https://github.com/approov/quickstart-php-laravel-token-check","last_synced_at":"2026-02-23T23:15:43.298Z","repository":{"id":54737092,"uuid":"300253615","full_name":"approov/quickstart-php-laravel-token-check","owner":"approov","description":"Quickstart Approov integration example for the PHP Laravel framework ","archived":false,"fork":false,"pushed_at":"2026-02-23T10:13:48.000Z","size":4581,"stargazers_count":3,"open_issues_count":10,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2026-02-23T18:56:10.248Z","etag":null,"topics":["api","api-key","api-key-authentication","api-keys","api-php","api-secret","api-secure","api-security","api-server","approov","approov-cloud-service","approov-quickstart","backend-service","jwt-validation","laravel","laravel-api","laravel-api-access-token","laravel-api-auth","laravel-api-authentication","php"],"latest_commit_sha":null,"homepage":"https://approov.io","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/approov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-10-01T11:24:31.000Z","updated_at":"2025-12-30T12:27:11.000Z","dependencies_parsed_at":"2024-08-23T10:26:57.210Z","dependency_job_id":"12f4de80-3869-4c16-836d-79791c3b9ab3","html_url":"https://github.com/approov/quickstart-php-laravel-token-check","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/approov/quickstart-php-laravel-token-check","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/approov%2Fquickstart-php-laravel-token-check","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/approov%2Fquickstart-php-laravel-token-check/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/approov%2Fquickstart-php-laravel-token-check/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/approov%2Fquickstart-php-laravel-token-check/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/approov","download_url":"https://codeload.github.com/approov/quickstart-php-laravel-token-check/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/approov%2Fquickstart-php-laravel-token-check/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29760254,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-23T21:02:23.375Z","status":"ssl_error","status_checked_at":"2026-02-23T20:58:31.539Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["api","api-key","api-key-authentication","api-keys","api-php","api-secret","api-secure","api-security","api-server","approov","approov-cloud-service","approov-quickstart","backend-service","jwt-validation","laravel","laravel-api","laravel-api-access-token","laravel-api-auth","laravel-api-authentication","php"],"created_at":"2024-11-11T14:35:05.831Z","updated_at":"2026-02-23T23:15:43.224Z","avatar_url":"https://github.com/approov.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Approov QuickStart - PHP Laravel Token Check\n\n[Approov](https://approov.io) is an API security solution used to verify that requests received by your backend services originate from trusted versions of your mobile apps.\n\nThis repo implements the Approov server-side request verification code in PHP, which performs the verification check before allowing valid traffic to be processed by the API endpoint.\n\nThis is an Approov integration quickstart example for the PHP Laravel framework. If you are looking for another PHP integration you can check our list of [quickstarts](https://approov.io/docs/latest/approov-integration-examples/backend-api/), and if you don't find what you are looking for, then please let us know [here](https://approov.io/contact). Meanwhile, you can always use the framework agnostic [quickstart example](https://github.com/approov/quickstart-php-token-check) for PHP, and you may find that's easily adaptable to your framework of choice.\n\n\n## Approov Integration Quickstart\n\nThe quickstart was tested with the following Operating Systems:\n\n* Ubuntu 20.04\n* MacOS Big Sur\n* Windows 10 WSL2 - Ubuntu 20.04\n\nFirst, setup the [Approov CLI](https://approov.io/docs/latest/approov-installation/index.html#initializing-the-approov-cli).\n\nNow, register the API domain for which Approov will issues tokens:\n\n```bash\napproov api -add api.example.com\n```\n\n\u003e **NOTE:** By default a symmetric key (HS256) is used to sign the Approov token on a valid attestation of the mobile app for each API domain it's added with the Approov CLI, so that all APIs will share the same secret and the backend needs to take care to keep this secret secure.\n\u003e\n\u003e A more secure alternative is to use asymmetric keys (RS256 or others) that allows for a different keyset to be used on each API domain and for the Approov token to be verified with a public key that can only verify, but not sign, Approov tokens.\n\u003e\n\u003e To implement the asymmetric key you need to change from using the symmetric HS256 algorithm to an asymmetric algorithm, for example RS256, that requires you to first [add a new key](https://approov.io/docs/latest/approov-usage-documentation/#adding-a-new-key), and then specify it when [adding each API domain](https://approov.io/docs/latest/approov-usage-documentation/#keyset-key-api-addition). Please visit [Managing Key Sets](https://approov.io/docs/latest/approov-usage-documentation/#managing-key-sets) on the Approov documentation for more details.\n\nNext, enable your Approov `admin` role with:\n\n```bash\neval `approov role admin`\n````\n\nFor the Windows powershell:\n\n```bash\nset APPROOV_ROLE=admin:___YOUR_APPROOV_ACCOUNT_NAME_HERE___\n```\n\nNow, get your Approov Secret with the [Approov CLI](https://approov.io/docs/latest/approov-installation/index.html#initializing-the-approov-cli):\n\n```bash\napproov secret -get base64\n```\n\n\u003e **@IMPORTANT:**\n\u003e Don't set an Approov key id for the secret, because the JWT library doesn't support to pass the symmetric key for the Approov secret in a JWKs.\n\nNext, add the [Approov secret](https://approov.io/docs/latest/approov-usage-documentation/#account-secret-key-export) to your project `.env` file:\n\n```env\nAPPROOV_BASE64_SECRET=approov_base64_secret_here\n```\n\nNow, let your Laravel app load it into the config, by creating a configuration file for Approov at `config/approov.php`:\n\n```php\n\u003c?php\n\nreturn [\n    'secret' =\u003e base64_decode(env('APPROOV_BASE64_SECRET'), true),\n];\n```\n\nNext, add to your project the [firebase/php-jwt](https://github.com/firebase/php-jwt) package to check the JWT token:\n\n```text\ncomposer require firebase/php-jwt\n```\n\nNow, add the [Approov Middleware](/src/approov-protected-server/token-check/hello/app/Http/Middleware/Approov.php) class to your project at `app/Http/Middleware/Approov.php`:\n\n```php\n\u003c?php declare(strict_types=1);\n\nnamespace App\\Http\\Middleware;\n\nuse Closure;\nuse Firebase\\JWT\\JWT;\nuse Symfony\\Component\\HttpFoundation\\HeaderBag;\n\nclass Approov\n{\n    /**\n     * Handle an incoming request.\n     *\n     * @param  \\Illuminate\\Http\\Request  $request\n     * @param  \\Closure  $next\n     * @return mixed\n     */\n    public function handle($request, Closure $next)\n    {\n        $approov_token_claims = $this-\u003everifyApproovToken($request-\u003eheaders);\n\n        if (!$approov_token_claims) {\n            return response()-\u003ejson(new \\stdClass(), 401);\n        }\n\n        return $next($request);\n    }\n\n    /**\n     * Verifies the Approov token in the incoming request.\n     *\n     * Returns the Approov token claims on success or null on failure.\n     *\n     * @param  Symfony\\Component\\HttpFoundation\\HeaderBag  $headers\n     * @return ?\\stdClass\n     */\n    private function verifyApproovToken(HeaderBag $headers): ?\\stdClass {\n        try {\n            $approov_token = $headers-\u003eget('Approov-Token');\n\n            if (empty($approov_token)) {\n                // You may want to add some logging here\n                // \\Log::debug(\"MISSING APPROOV TOKEN\");\n                return null;\n            }\n\n            $approov_secret = config('approov.secret');\n\n            if (empty($approov_secret)) {\n                // You may want to add some logging here\n                //\\Log::debug(\"MISSING APPROOV SECRET\");\n                return null;\n            }\n\n            // The Approov secret cannot be given as part of a JWKS key set,\n            // therefore you cannot use the Approov CLI to set a key id for it.\n            //\n            // If you set the key id then the token check will fail due to the\n            // presence of a `kid` key in the header of the Approov token, that\n            // will not be found in the `$approov_secret` variable, because this\n            // variable contains the secret as a binary string, not as a JWKs\n            // key set.\n            $approov_token_claims = JWT::decode($approov_token, $approov_secret, ['HS256']);\n            return $approov_token_claims;\n\n        } catch(\\UnexpectedValueException $exception) {\n            // You may want to add some logging here\n            // \\Log::debug($exception-\u003egetMessage());\n            return null;\n        } catch(\\InvalidArgumentException $exception) {\n            // You may want to add some logging here\n            // \\Log::debug($exception-\u003egetMessage());\n            return null;\n        } catch(\\DomainException $exception) {\n            // You may want to add some logging here\n            // \\Log::debug($exception-\u003egetMessage());\n            return null;\n        }\n\n        // You may want to add some logging here\n        return null;\n    }\n}\n```\n\nNext, add the [Approov Middleware](/src/approov-protected-server/token-check/hello/app/Http/Middleware/Approov.php) to your Laravel application route middleware array at [app/Http/Kernel.php](/src/approov-protected-server/token-check/hello/app/Http/Kernel.php):\n\n```php\nprotected $routeMiddleware = [\n    'approov' =\u003e \\App\\Http\\Middleware\\Approov::class,\n    'auth' =\u003e \\App\\Http\\Middleware\\Authenticate::class,\n    // omitted lines for brevity\n];\n```\n\nIn the same file, you need to activate the Approov Middleware by including it as the first one in the array for the `api` route middleware group:\n\n```php\nprotected $middlewareGroups = [\n    'web' =\u003e [\n        // omitted lines for brevity\n    ],\n\n    'api' =\u003e [\n        'approov',\n        'throttle:60,1',\n        \\Illuminate\\Routing\\Middleware\\SubstituteBindings::class,\n    ],\n];\n```\n\n\u003e **NOTE:** The Approov middleware is included as the first one in the array because you don't want to waste your server resources in processing requests that don't have a valid Approov token. This approach will help your server to handle more load under a Denial of Service(DoS) attack.\n\nAdding the Approov Middleware class to the `api` middleware group means that any incoming request to an API route needs to have a valid Approov token to be further processed. So, no need to explicitly add Approov as a middleware into any route in the file `routes/api.php`.\n\nYou can skip the Approov Middleware execution for any given route by using:\n\n```php\nRoute::get('/some-route', function () {\n    // your code here\n})-\u003ewithoutMiddleware(['approov']);\n```\n\nNot enough details in the bare bones quickstart? No worries, check the [detailed quickstarts](QUICKSTARTS.md) that contain a more comprehensive set of instructions, including how to test the Approov integration.\n\n\n## More Information\n\n* [Approov Overview](OVERVIEW.md)\n* [Detailed Quickstarts](QUICKSTARTS.md)\n* [Examples](EXAMPLES.md)\n* [Testing](TESTING.md)\n\n### System Clock\n\nIn order to correctly check for the expiration times of the Approov tokens is very important that the backend server is synchronizing automatically the system clock over the network with an authoritative time source. In Linux this is usually done with a NTP server.\n\n\n## Issues\n\nIf you find any issue while following our instructions then just report it [here](https://github.com/approov/quickstart-php-laravel-token-check/issues), with the steps to reproduce it, and we will sort it out and/or guide you to the correct path.\n\n\n## Useful Links\n\nIf you wish to explore the Approov solution in more depth, then why not try one of the following links as a jumping off point:\n\n* [Approov Free Trial](https://approov.io/signup)(no credit card needed)\n* [Approov Get Started](https://approov.io/product/demo)\n* [Approov QuickStarts](https://approov.io/docs/latest/approov-integration-examples/)\n* [Approov Docs](https://approov.io/docs)\n* [Approov Blog](https://approov.io/blog/)\n* [Approov Resources](https://approov.io/resource/)\n* [Approov Customer Stories](https://approov.io/customer)\n* [Approov Support](https://approov.io/contact)\n* [About Us](https://approov.io/company)\n* [Contact Us](https://approov.io/contact)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapproov%2Fquickstart-php-laravel-token-check","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapproov%2Fquickstart-php-laravel-token-check","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapproov%2Fquickstart-php-laravel-token-check/lists"}