1 | /// <reference types="grecaptcha" />
|
2 | import { InjectionToken } from "@angular/core";
|
3 | import { RecaptchaSettings } from "./recaptcha-settings";
|
4 | /** @deprecated Use `LOADER_OPTIONS` instead. See `RecaptchaLoaderOptions.onBeforeLoad` */
|
5 | export declare const RECAPTCHA_LANGUAGE: InjectionToken<string>;
|
6 | /** @deprecated Use `LOADER_OPTIONS` instead. See `RecaptchaLoaderOptions.onBeforeLoad` */
|
7 | export declare const RECAPTCHA_BASE_URL: InjectionToken<string>;
|
8 | /** @deprecated Use `LOADER_OPTIONS` instead. See `RecaptchaLoaderOptions.onBeforeLoad` */
|
9 | export declare const RECAPTCHA_NONCE: InjectionToken<string>;
|
10 | export declare const RECAPTCHA_SETTINGS: InjectionToken<RecaptchaSettings>;
|
11 | export declare const RECAPTCHA_V3_SITE_KEY: InjectionToken<string>;
|
12 | /**
|
13 | * Specifies the options for loading the reCAPTCHA script tag.
|
14 | */
|
15 | export type RecaptchaLoaderOptions = {
|
16 | /**
|
17 | * Invoked before the `<script>` tag is appended to the DOM.
|
18 | * Use this function as an opportunity to set `nonce`, as well as modify the URL of the tag.
|
19 | *
|
20 | * Use the `url.searchParams` to set additional query string attributes (including reCAPTCHA language),
|
21 | * or use an entirely different base URL altogether.
|
22 | *
|
23 | * The URL that you provide will then properly set the `"render"` and `"onload"` attributes which are required for proper `ng-recaptcha` wire-up.
|
24 | *
|
25 | * @param url the current URL that was composed. Either modify it in-place, or return a completely new URL.
|
26 | * @returns the final URL that is going to be used as the `src` for the `<script>` tag, along with (optionally) a nonce.
|
27 | *
|
28 | * @example
|
29 | * Provide nonce:
|
30 | * ```ts
|
31 | * {
|
32 | * provide: RECAPTCHA_LOADER_OPTIONS,
|
33 | * useValue: {
|
34 | * onBeforeLoad(url) {
|
35 | * return {
|
36 | * url,
|
37 | * nonce: "YOUR_NONCE"
|
38 | * };
|
39 | * }
|
40 | * }
|
41 | * }
|
42 | * ```
|
43 | *
|
44 | * Set the reCAPTCHA language:
|
45 | * ```ts
|
46 | * {
|
47 | * provide: RECAPTCHA_LOADER_OPTIONS,
|
48 | * useValue: {
|
49 | * onBeforeLoad(url) {
|
50 | * url.searchParams.set("hl", "en-GB")
|
51 | *
|
52 | * return { url };
|
53 | * }
|
54 | * }
|
55 | * }
|
56 | * ```
|
57 | *
|
58 | * Use a different base URL for loading reCAPTCHA
|
59 | * ```ts
|
60 | * {
|
61 | * provide: RECAPTCHA_LOADER_OPTIONS,
|
62 | * useValue: {
|
63 | * onBeforeLoad(_url) {
|
64 | * const chinaCompatibleUrl = new URL("https://www.recaptcha.net/recaptcha/api.js");
|
65 | * // optionally, set the locale:
|
66 | * // chinaCompatibleUrl.searchParams.set("hl", "zh-CN");
|
67 | *
|
68 | * return {
|
69 | * url: chinaCompatibleUrl
|
70 | * };
|
71 | * }
|
72 | * }
|
73 | * }
|
74 | * ```
|
75 | */
|
76 | onBeforeLoad?(url: URL): {
|
77 | url: URL;
|
78 | nonce?: string;
|
79 | };
|
80 | /**
|
81 | * Allows you to change the `grecaptcha` that the `ng-recaptcha` will be relying on.
|
82 | * This method is useful when you need to use `grecaptcha.enterprise` instead of the base `grecaptcha`
|
83 | *
|
84 | * @param recaptcha the value of `window.grecaptcha` upon script load.
|
85 | * @returns the {ReCaptchaV2.ReCaptcha} instance that the `ng-recaptcha` lib will use.
|
86 | *
|
87 | * @example
|
88 | * Using the Enterprise version of `grecaptcha`:
|
89 | *
|
90 | * ```ts
|
91 | * {
|
92 | * provide: RECAPTCHA_LOADER_OPTIONS,
|
93 | * useValue: {
|
94 | * onBeforeLoad() {
|
95 | * const recaptchaEnterpriseUrl = new URL("https://www.google.com/recaptcha/enterprise.js");
|
96 | * // optionally, if you're using the reCAPTCHA session-tokens, set the `&waf=session` param,
|
97 | * // see https://cloud.google.com/recaptcha-enterprise/docs/implement-waf-ca#session-token
|
98 | * // recaptchaEnterpriseUrl.searchParams.set("waf", "session");
|
99 | *
|
100 | * return {
|
101 | * url: recaptchaEnterpriseUrl,
|
102 | * }
|
103 | * },
|
104 | * onLoaded(recaptcha) {
|
105 | * return recaptcha.enterprise;
|
106 | * }
|
107 | * }
|
108 | * }
|
109 | * ```
|
110 | */
|
111 | onLoaded?(recaptcha: ReCaptchaV2.ReCaptcha): ReCaptchaV2.ReCaptcha;
|
112 | };
|
113 | /**
|
114 | * See the documentation for `RecaptchaLoaderOptions`.
|
115 | */
|
116 | export declare const RECAPTCHA_LOADER_OPTIONS: InjectionToken<RecaptchaLoaderOptions>;
|