{"id":19645789,"url":"https://github.com/approov/quickstart-ruby-token-check","last_synced_at":"2025-06-27T16:31:41.468Z","repository":{"id":54737172,"uuid":"295690455","full_name":"approov/quickstart-ruby-token-check","owner":"approov","description":"Quickstart Approov integration example for Ruby without depending on a framework. ","archived":false,"fork":false,"pushed_at":"2022-12-20T18:56:06.000Z","size":52,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-06-01T14:58:21.149Z","etag":null,"topics":["api","api-security","approov","approov-backend","approov-backend-quicksart","approov-integration","approov-quickstart","security"],"latest_commit_sha":null,"homepage":"https://approov.io","language":"Ruby","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}},"created_at":"2020-09-15T10:18:57.000Z","updated_at":"2023-02-08T16:50:28.000Z","dependencies_parsed_at":"2023-01-30T01:30:19.581Z","dependency_job_id":null,"html_url":"https://github.com/approov/quickstart-ruby-token-check","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/approov/quickstart-ruby-token-check","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/approov%2Fquickstart-ruby-token-check","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/approov%2Fquickstart-ruby-token-check/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/approov%2Fquickstart-ruby-token-check/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/approov%2Fquickstart-ruby-token-check/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/approov","download_url":"https://codeload.github.com/approov/quickstart-ruby-token-check/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/approov%2Fquickstart-ruby-token-check/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262293022,"owners_count":23288645,"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":["api","api-security","approov","approov-backend","approov-backend-quicksart","approov-integration","approov-quickstart","security"],"created_at":"2024-11-11T14:35:14.453Z","updated_at":"2025-06-27T16:31:41.423Z","avatar_url":"https://github.com/approov.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Approov QuickStart - Ruby 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 Ruby (framework agnostic), which performs the verification check before allowing valid traffic to be processed by the API endpoint.\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\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, to check the Approov token we will use the [jwt/ruby-jwt](https://github.com/jwt/ruby-jwt) package, that you can install with:\n\n```bash\ngem install jwt\n```\n\n\u003e **NOTE:** If you are not using yet the `dotenv` package then you also nee to add it to the install command.\n\nNext, add this code to your project:\n\n```ruby\nrequire 'dotenv'\nrequire 'jwt'\nrequire 'base64'\n\nenv = Dotenv.parse(\".env\")\n\nif not env['HTTP_PORT']\n    env['HTTP_PORTP'] = 8002\nend\n\nif not env['SERVER_HOSTNAME']\n    env['SERVER_HOSTNAME'] = '127.0.0.1'\nend\n\nif not env['APPROOV_BASE64_SECRET']\n    raise \"Missing in the .env file the value for the variable: APPROOV_BASE64_SECRET\"\nend\n\nAPPROOV_SECRET = Base64.decode64(env['APPROOV_BASE64_SECRET'])\n\ndef verifyApproovToken headers\n    begin\n        approov_token = headers['approov-token']\n\n        if not approov_token\n            # You may want to add some logging here\n            return nil\n        end\n\n        options = { algorithm: 'HS256' }\n        approov_token_claims, header = JWT.decode approov_token, APPROOV_SECRET, true, options\n\n        return approov_token_claims\n    rescue JWT::DecodeError =\u003e e\n        # You may want to add some logging here\n        return nil\n    rescue JWT::ExpiredSignature =\u003e e\n        # You may want to add some logging here\n        return nil\n    rescue JWT::InvalidIssuerError =\u003e e\n        # You may want to add some logging here\n        return nil\n    rescue JWT::InvalidIatError\n        # You may want to add some logging here\n        return nil\n    end\n\n    # You may want to add some logging here\n    return nil\nend\n```\n\nNow you just need to invoke `verifyApproovToken()` function for the endpoints you want to protected:\n\n```ruby\nif not approov_token_claims = verifyApproovToken(headers)\n    sendResponse(connection, 401, JSON.generate({}))\n    next\nend\n```\n\n\u003e **NOTE:** When the Approov token validation fails we return a `401` with an empty body, because we don't want to give clues to an attacker about the reason the request failed, and you can go even further by returning a `400`.\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### 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-ruby-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-ruby-token-check","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapproov%2Fquickstart-ruby-token-check","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapproov%2Fquickstart-ruby-token-check/lists"}