{"id":19928602,"url":"https://github.com/enngage/ngx-captcha","last_synced_at":"2025-04-04T14:07:29.524Z","repository":{"id":29923268,"uuid":"122954842","full_name":"Enngage/ngx-captcha","owner":"Enngage","description":"ReCaptcha components for Angular. Live preview:","archived":false,"fork":false,"pushed_at":"2023-05-04T14:59:21.000Z","size":6005,"stargazers_count":153,"open_issues_count":14,"forks_count":48,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-01T22:17:34.013Z","etag":null,"topics":["angular","captcha","recaptcha"],"latest_commit_sha":null,"homepage":"https://enngage.github.io/ngx-captcha/","language":"TypeScript","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/Enngage.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":"2018-02-26T10:38:52.000Z","updated_at":"2025-01-11T14:32:38.000Z","dependencies_parsed_at":"2024-06-18T12:40:43.405Z","dependency_job_id":"657adcc1-2879-419c-bd73-1c282bf244d4","html_url":"https://github.com/Enngage/ngx-captcha","commit_stats":{"total_commits":245,"total_committers":12,"mean_commits":"20.416666666666668","dds":0.0897959183673469,"last_synced_commit":"6cbe62efede6cba64c99cce9f6d99eee37cd6569"},"previous_names":[],"tags_count":49,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Enngage%2Fngx-captcha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Enngage%2Fngx-captcha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Enngage%2Fngx-captcha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Enngage%2Fngx-captcha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Enngage","download_url":"https://codeload.github.com/Enngage/ngx-captcha/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247190250,"owners_count":20898702,"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":["angular","captcha","recaptcha"],"created_at":"2024-11-12T22:37:43.627Z","updated_at":"2025-04-04T14:07:29.507Z","avatar_url":"https://github.com/Enngage.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm version](https://badge.fury.io/js/ngx-captcha.svg)](https://badge.fury.io/js/ngx-captcha)\n[![Build Status](https://api.travis-ci.org/Enngage/ngx-captcha.svg?branch=master)](https://travis-ci.org/Enngage/ngx-captcha)\n[![NPM](https://nodei.co/npm/ngx-captcha.png?mini=true)](https://nodei.co/npm/ngx-captcha/)\n\n## Angular Captcha\n\nGoogle reCaptcha implementation for Angular 14.\n\nFeatures: \n\n1. reCaptcha v2\n2. reCaptcha v3 (beta)\n3. invisible reCaptcha\n\nLive examples: [https://enngage.github.io/ngx-captcha/](https://enngage.github.io/ngx-captcha/)\n\n## Installation\n\n```javascript\nnpm install ngx-captcha\n```\n\nImport `NgxCaptchaModule ` to your module (i.e. `AppModule`)\n\n### Use with Angular forms\n\nDepending on whether you want to use [reactive forms](https://angular.io/guide/reactive-forms) or [template-driven forms](https://angular.io/guide/forms) you need to include the appropriate modules, too.\nAdd `ReactiveFormsModule` to your imports in case you want to use reactive forms. If you prefer the the template-driven approach simple add the `FormsModule` to your module. \n\nBoth can be imported from `@angular/forms`. In the demo project you can check out the *normal* demo to see how to use reactive forms or the *invisible* demo to see what the template-driven approach looks like. With the template-driven approach you don't necessarily need to use a from element to wrap the component, you can instead use the `[ngModelOptions]=\"{ standalone: true }\"`.\nHowever, using it with the standalone option is not recommended but can be used if needed. \n\n```javascript\nimport { NgModule } from '@angular/core';\nimport { ReactiveFormsModule } from '@angular/forms';\nimport { NgxCaptchaModule } from 'ngx-captcha';\n\n@NgModule({\n  imports: [\n    ReactiveFormsModule,\n    NgxCaptchaModule\n  })\n\nexport class AppModule { }\n```\n\n## Usage\nThe configuration properties are a copy of the official ones that google provides. For explanation of what these properties do and how to use them, please refer to [https://developers.google.com/recaptcha/docs/display](https://developers.google.com/recaptcha/docs/display) and [https://developers.google.com/recaptcha/docs/invisible](https://developers.google.com/recaptcha/docs/invisible).\n\n### reCaptcha v2\n\nyour.component.ts\n```typescript\nexport class YourComponent implements OnInit {\n  protected aFormGroup: FormGroup;\n\n  constructor(private formBuilder: FormBuilder) {}\n\n  ngOnInit() {\n    this.aFormGroup = this.formBuilder.group({\n      recaptcha: ['', Validators.required]\n    });\n  }\n}\n```\n\nyour.template.html\n```html\n\u003cform [formGroup]=\"aFormGroup\"\u003e\n  \u003cngx-recaptcha2 #captchaElem\n    [siteKey]=\"siteKey\"\n    (reset)=\"handleReset()\"\n    (expire)=\"handleExpire()\"\n    (load)=\"handleLoad()\"\n    (success)=\"handleSuccess($event)\"\n    [useGlobalDomain]=\"false\"\n    [size]=\"size\"\n    [hl]=\"lang\"\n    [theme]=\"theme\"\n    [type]=\"type\"\n    formControlName=\"recaptcha\"\u003e\n  \u003c/ngx-recaptcha2\u003e\n\u003c/form\u003e\n```\n\n### reCaptcha v3\n\n This is the implementation of \u003cem\u003ebeta\u003c/em\u003e version of google reCaptcha v3 as per following documentation[\"https://developers.google.com/recaptcha/docs/v3\"](https://developers.google.com/recaptcha/docs/v3).\n\n First you need to inject the \u003cem\u003e\u003c/em\u003e class in your component / service and then use \u003cem\u003eExecute\u003c/em\u003e method with your action. Once you have the token, you need to verify it on your backend to get meaningful results. See official google documentation for more details.\n\n ```typescript\n import { ReCaptchaV3Service } from 'ngx-captcha';\n\n  constructor(\n    private reCaptchaV3Service: ReCaptchaV3Service\n  ) { }\n\n  ....\n\n  this.reCaptchaV3Service.execute(this.siteKey, 'homepage', (token) =\u003e {\n    console.log('This is your token: ', token);\n  }, {\n      useGlobalDomain: false\n  });\n ```\n\n### Invisible reCaptcha\n\n```html\n\u003cform [formGroup]=\"aFormGroup\"\u003e\n  \u003cngx-invisible-recaptcha #captchaElem\n    [siteKey]=\"siteKey\"\n    (reset)=\"handleReset()\"\n    (ready)=\"handleReady()\"\n    (load)=\"handleLoad()\"\n    (success)=\"handleSuccess($event)\"\n    [useGlobalDomain]=\"false\"\n    [type]=\"type\"\n    [badge]=\"badge\"\n    [ngModel]=\"recaptcha\"\n    [ngModelOptions]=\"{ standalone: true }\"\u003e\n  \u003c/ngx-invisible-recaptcha\u003e\n\u003c/form\u003e\n```\n\n### Unit testing\n\nUnit testing in Angular is possible, but a bit clunky because this component tries to dynamically include google's script if its not already loaded. You are not required to include in globally or manually which has a benefit of not loading until you actually use this component. This has a caveat though, since the `load` callback is executed outside of Angular's zone, performing unit tests might fail due to racing condition where Angular might fail the test before the script has a chance to load and initialize captcha. \n\nA simple fix for this is wait certain amount of time so that everything has a chance to initialize. See example below:\n\n```typescript\nbeforeEach(() =\u003e {\n        fixture = TestBed.createComponent(YourComponent);\n        component = fixture.componentInstance;\n        setTimeout(function () {\n            fixture.detectChanges();\n        }, 2000);\n});\n```\n\nOther possible scenario might be including google's script globally. If someone has a better solution, please do let me know or submit a PR for a change in readme.\n\n### Publishing lib\n\nUnder `projects\\ngx-captcha-lib` run \n\n```\nnpm run publish:lib\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenngage%2Fngx-captcha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenngage%2Fngx-captcha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenngage%2Fngx-captcha/lists"}