{"id":19107190,"url":"https://github.com/govtechsg/myinfo-rails","last_synced_at":"2025-07-31T12:33:44.843Z","repository":{"id":39612568,"uuid":"330535143","full_name":"GovTechSG/myinfo-rails","owner":"GovTechSG","description":"Rails Wrapper for MyInfo API","archived":false,"fork":false,"pushed_at":"2023-12-26T13:15:23.000Z","size":155,"stargazers_count":3,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-19T08:10:28.353Z","etag":null,"topics":["myinfo","rails","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/GovTechSG.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2021-01-18T02:35:45.000Z","updated_at":"2023-11-09T04:54:02.000Z","dependencies_parsed_at":"2023-12-26T15:13:28.607Z","dependency_job_id":"1fcb9660-682f-4a44-883f-fe639031bf26","html_url":"https://github.com/GovTechSG/myinfo-rails","commit_stats":{"total_commits":68,"total_committers":5,"mean_commits":13.6,"dds":"0.27941176470588236","last_synced_commit":"b59b5d542539a2b551e2989447d4732303c4c7a1"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GovTechSG%2Fmyinfo-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GovTechSG%2Fmyinfo-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GovTechSG%2Fmyinfo-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GovTechSG%2Fmyinfo-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GovTechSG","download_url":"https://codeload.github.com/GovTechSG/myinfo-rails/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251758243,"owners_count":21639003,"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":["myinfo","rails","ruby"],"created_at":"2024-11-09T04:11:34.635Z","updated_at":"2025-04-30T18:21:35.268Z","avatar_url":"https://github.com/GovTechSG.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rails wrapper for MyInfo API\n\n![tests](https://github.com/GovTechSG/myinfo/workflows/tests/badge.svg?branch=main)\n\n# MyInfo V4\n\n[MyInfo Documentation (Public)](https://public.cloud.myinfo.gov.sg/myinfo/api/myinfo-kyc-v4.0.html)\n\nNote: Currently this gem only supports `public_facing = true` for MyInfo V4 API.\n\n## Basic Setup (Public)\n\n1. `bundle add myinfo`\n2. Create a `config/initializers/myinfo.rb` and add the required configuration based on your environment.\n```ruby\n  MyInfo.configure do |config|\n    config.app_id = ''\n    config.client_id = ''\n    config.client_secret = ''\n    config.base_url = 'test.api.myinfo.gov.sg'\n    config.redirect_uri = 'https://localhost:3001/callback'\n    config.public_facing = true\n    config.sandbox = false # optional, false by default\n    config.private_encryption_key = ''\n    config.private_signing_key = ''\n    config.authorise_jwks_base_url = \"test.authorise.singpass.gov.sg\"\n    # setup proxy here if needed\n    config.proxy = { address: 'proxy_address', port: 'proxy_port' } # optional, nil by default\n    config.gateway_url = 'https://test_gateway_url' # optional, nil by default\n    config.gateway_key = '44d953c796cccebcec9bdc826852857ab412fbe2' # optional, nil by default\n  end\n```\n\n3. Generate the code verifier and code challenge and manage a session to their frontend to link the code_verifier and code_challenge.\n```ruby\ncode_verifier, code_challenge = MyInfo::V4::Session.call\n```\n\n4. On callback url triggered, obtain a `MyInfo::V4::Token`. This token can only be used once.\n\n```ruby\nkey_pairs = SecurityHelper.generate_session_key_pair\nresponse = MyInfo::V4::Token.call(\n  key_pairs: key_pairs,\n  auth_code: params[:code],\n  code_verifier: session[:code_verifier]\n)\n\naccess_token = response.data\n```\n\n5. Obtain the `access_token` from the `response` and query for `MyInfo::V4::Person`:\n```ruby\nresponse = MyInfo::V4::Person.call(key_pairs: key_pairs, access_token: access_token)\n```\n\n\n# MyInfo V3\n\n[MyInfo Documentation (Public)](https://public.cloud.myinfo.gov.sg/myinfo/api/myinfo-kyc-v3.1.0.html)\n\n[MyInfo Documentation (Government)](https://public.cloud.myinfo.gov.sg/myinfo/tuo/myinfo-tuo-specs.html)\n\n## Basic Setup (Public)\n\n1. `bundle add myinfo`\n2. Create a `config/initializers/myinfo.rb` and add the required configuration based on your environment.\n```ruby\n  MyInfo.configure do |config|\n    config.app_id = ''\n    config.client_id = ''\n    config.client_secret = ''\n    config.base_url = 'test.api.myinfo.gov.sg'\n    config.redirect_uri = 'https://localhost:3001/callback'\n    config.public_facing = true\n    config.private_key = File.read(Rails.root.join('private_key_location'))\n    config.public_cert = File.read(Rails.root.join('public_cert_location'))\n    config.sandbox = false # optional, false by default\n    config.proxy = { address: 'proxy_address', port: 'proxy_port' } # optional, nil by default\n    config.gateway_url = 'https://test_gateway_url' # optional, nil by default\n    config.gateway_key = '44d953c796cccebcec9bdc826852857ab412fbe2' # optional, nil by default\n  end\n```\n\n3. To obtain a person's MyInfo information, we need to authorise the query first:\n```ruby\nredirect_to MyInfo::V3::AuthoriseUrl.call(\n      purpose: 'set your purpose here',\n      state: SecureRandom.hex # set a state to check on callback\n    )\n```\n\n4. On `redirect_url`, obtain a `MyInfo::V3::Token`. This token can only be used once.\n```ruby\n    response = MyInfo::V3::Token.call(\n      code: params[:code],\n      state: params[:state]\n    )\n```\n\n5. Obtain the `access_token` from the `response` and query for `MyInfo::V3::Person`:\n```ruby\nresult = MyInfo::V3::Person.call(access_token: response.data) if response.success?\n```\n\n## Basic Setup (Government)\n\n1. `bundle add myinfo`\n2. Create a `config/initializers/myinfo.rb` and add the required configuration based on your environment.\n```ruby\n  MyInfo.configure do |config|\n    config.app_id = ''\n    config.client_id = ''\n    config.client_secret = ''\n    config.base_url = 'test.api.myinfo.gov.sg'\n    config.redirect_uri = 'https://localhost:3001/callback'\n    config.singpass_eservice_id = 'MYINFO-CONSENTPLATFORM'\n    config.private_key = File.read(Rails.root.join('private_key_location'))\n    config.public_cert = File.read(Rails.root.join('public_cert_location'))\n    config.sandbox = false # optional, false by default\n    config.proxy = { address: 'proxy_address', port: 'proxy_port' } # optional, nil by default\n    config.gateway_url = 'https://test_gateway_url' #optional, nil by default\n    config.gateway_key = '44d953c796cccebcec9bdc826852857ab412fbe2' #optional, nil by default\n  end\n```\n\n3. To obtain a person's MyInfo information, we need to authorise the query first:\n```ruby\nredirect_to MyInfo::V3::AuthoriseUrl.call(\n      nric_fin: \"user's NRIC\", # see documentation for list of sample NRICs\n      purpose: 'set your purpose here',\n      state: SecureRandom.hex # set a state to check on callback\n    )\n```\n\n4. On `redirect_url`, obtain a `MyInfo::V3::Token`. This token can only be used once.\n```ruby\n    response = MyInfo::V3::Token.call(\n      code: params[:code],\n      state: params[:state]\n    )\n```\n\n5. Obtain the `access_token` from the `response` and query for `MyInfo::V3::Person`:\n```ruby\nresult = MyInfo::V3::Person.call(access_token: response.data) if response.success?\n```\n\n## Sample App Demo\n\n1. `git clone git@github.com:GovTechSG/myinfo-rails.git`\n2. `cd myinfo-rails`\n3. `bundle install`\n4. `cd spec/dummy \u0026\u0026 rails s`\n5. Navigate to `localhost:3001`\n\n## Advanced\n- `attributes` can be passed to `AuthoriseUrl` and `Person` as an array to override the default attributes queried - check MyInfo for a list of available attributes.\n\n- `success?` can be called on `MyInfo::V3::Response` to determine whether the query has succeeded or failed. Check MyInfo API for a list of responses and how to handle them.\n\n## Disclaimer\nProvided credentials in the repository are either obtained from [MyInfo Demo App](https://github.com/ndi-trusted-data/myinfo-demo-app) or samples online, and are only for testing purposes. They should not be re-used for staging or production environments. Visit the [official MyInfo tutorial](https://www.ndi-api.gov.sg/library/myinfo/tutorial3) for more information.\n\n## Contributing\n\nContributions are welcome!\n\n1. Fork the repository\n2. Write code and tests\n3. Submit a PR\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgovtechsg%2Fmyinfo-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgovtechsg%2Fmyinfo-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgovtechsg%2Fmyinfo-rails/lists"}