http-client-with-recaptcha 1.0.0 β 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +188 -0
- package/package.json +2 -2
package/README.md
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
|
2
|
+
# `http-client-with-recaptcha` - Angular Service for HTTP Requests with reCAPTCHA v3 Integration
|
3
|
+
|
4
|
+
## π Introduction
|
5
|
+
|
6
|
+
Welcome to `http-client-with-recaptcha`, an Angular service designed to seamlessly integrate Google's reCAPTCHA v3 into your HTTP requests. This service allows you to attach reCAPTCHA tokens to headers in your HTTP requests, ensuring secure interactions with your API endpoints.
|
7
|
+
|
8
|
+
With this package, you can easily incorporate reCAPTCHA protection without worrying about manual token management, all while keeping your code clean and maintainable.
|
9
|
+
|
10
|
+
---
|
11
|
+
|
12
|
+
## π¦ Features
|
13
|
+
|
14
|
+
- **Easy Integration**: Add reCAPTCHA protection to HTTP requests in Angular effortlessly.
|
15
|
+
- **Customizable Header Name**: Set the reCAPTCHA token header name globally for your application.
|
16
|
+
- **Flexible HTTP Methods**: Supports `GET`, `POST`, and any other HTTP method, while automatically including reCAPTCHA tokens in headers.
|
17
|
+
- **Seamless reCAPTCHA v3 Integration**: Works directly with Google's invisible reCAPTCHA v3.
|
18
|
+
- **Configurable**: Easily customize token handling and header names via Angular's dependency injection.
|
19
|
+
|
20
|
+
---
|
21
|
+
|
22
|
+
## π§ Installation
|
23
|
+
|
24
|
+
### 1. Install Dependencies
|
25
|
+
|
26
|
+
Add this library (`http-client-with-recaptcha`) to your project:
|
27
|
+
|
28
|
+
```bash
|
29
|
+
npm install http-client-with-recaptcha --save
|
30
|
+
```
|
31
|
+
|
32
|
+
### 2. Import the Module
|
33
|
+
|
34
|
+
In your Angular module (`app.module.ts`), import the `HttpClientWithRecaptchaModule` and include it in the `imports` array.
|
35
|
+
|
36
|
+
```typescript
|
37
|
+
import { HttpClientWithRecaptchaModule } from 'http-client-with-recaptcha';
|
38
|
+
|
39
|
+
@NgModule({
|
40
|
+
imports: [
|
41
|
+
importProvidersFrom(HttpClientWithRecaptchaModule),
|
42
|
+
{
|
43
|
+
provide: RECAPTCHA_V3_KEY,
|
44
|
+
useValue: environment.reCaptchaV3Token, // Replace with an actual site key or inject dynamically
|
45
|
+
},
|
46
|
+
|
47
|
+
{
|
48
|
+
provide: RECAPTCHA_HEADER_NAME,
|
49
|
+
useValue: 'recaptchaaaaaa', // Replace with an actual site key or inject dynamically
|
50
|
+
},
|
51
|
+
// other imports...
|
52
|
+
],
|
53
|
+
// other properties...
|
54
|
+
})
|
55
|
+
export class AppModule {}
|
56
|
+
```
|
57
|
+
|
58
|
+
---
|
59
|
+
|
60
|
+
## 𧩠Usage
|
61
|
+
|
62
|
+
### Step 1: Inject the Service
|
63
|
+
|
64
|
+
Inject the `HttpClientWithRecaptcha` service into your component or service:
|
65
|
+
|
66
|
+
```typescript
|
67
|
+
import { HttpClientWithRecaptcha } from 'http-client-with-recaptcha';
|
68
|
+
|
69
|
+
@Injectable({
|
70
|
+
providedIn: 'root',
|
71
|
+
})
|
72
|
+
export class MyService {
|
73
|
+
constructor(private httpClientWithRecaptcha: HttpClientWithRecaptcha) {}
|
74
|
+
|
75
|
+
fetchData() {
|
76
|
+
return this.http.post<YOUR_INTERFACE>(
|
77
|
+
'https://example.com/api',
|
78
|
+
{__BODY__},
|
79
|
+
'login' // 'login' is a reCAPTCHA v3 action
|
80
|
+
);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
```
|
84
|
+
|
85
|
+
### Step 2: Customize the Header (Optional)
|
86
|
+
|
87
|
+
You can customize the reCAPTCHA token header globally in your `AppModule`:
|
88
|
+
|
89
|
+
```typescript
|
90
|
+
import { RECAPTCHA_HEADER_NAME } from 'http-client-with-recaptcha';
|
91
|
+
|
92
|
+
@NgModule({
|
93
|
+
providers: [
|
94
|
+
{
|
95
|
+
provide: RECAPTCHA_HEADER_NAME,
|
96
|
+
useValue: 'X-YOUR-Recaptcha-V3-Token', // Customize header name
|
97
|
+
},
|
98
|
+
],
|
99
|
+
})
|
100
|
+
export class AppModule {}
|
101
|
+
```
|
102
|
+
|
103
|
+
---
|
104
|
+
|
105
|
+
## π Configuration
|
106
|
+
|
107
|
+
### Dynamic Header Name
|
108
|
+
|
109
|
+
By default, the service uses `X-Recaptcha-Token` as the header name, but you can configure it globally through Angular's dependency injection system.
|
110
|
+
|
111
|
+
```typescript
|
112
|
+
import { RECAPTCHA_HEADER_NAME } from 'http-client-with-recaptcha';
|
113
|
+
|
114
|
+
@NgModule({
|
115
|
+
providers: [
|
116
|
+
{
|
117
|
+
provide: RECAPTCHA_HEADER_NAME,
|
118
|
+
useValue: 'X-Your-Recaptcha-Token', // Set dynamic header name
|
119
|
+
},
|
120
|
+
],
|
121
|
+
})
|
122
|
+
export class AppModule {}
|
123
|
+
```
|
124
|
+
|
125
|
+
---
|
126
|
+
|
127
|
+
## βοΈ Methods
|
128
|
+
|
129
|
+
### `withRecaptcha(action: string): HttpClientWithRecaptcha`
|
130
|
+
|
131
|
+
- **Description**: Attach a reCAPTCHA token to the HTTP request header.
|
132
|
+
- **Parameters**:
|
133
|
+
- `action`: The action string for reCAPTCHA v3 (e.g., `login`, `signup`).
|
134
|
+
- **Returns**: An instance of `HttpClientWithRecaptcha` for chaining.
|
135
|
+
|
136
|
+
### `get<T>(url: string, options: any): Observable<T>`
|
137
|
+
|
138
|
+
- **Description**: Perform a `GET` request with reCAPTCHA protection.
|
139
|
+
- **Parameters**:
|
140
|
+
- `url`: The API endpoint to send the GET request.
|
141
|
+
- `options`: Optional additional HTTP options.
|
142
|
+
- **Returns**: An observable of the HTTP response.
|
143
|
+
|
144
|
+
### `post<T>(url: string, body: any, options: any): Observable<T>`
|
145
|
+
|
146
|
+
- **Description**: Perform a `POST` request with reCAPTCHA protection.
|
147
|
+
- **Parameters**:
|
148
|
+
- `url`: The API endpoint to send the POST request.
|
149
|
+
- `body`: The body data for the POST request.
|
150
|
+
- `options`: Optional additional HTTP options.
|
151
|
+
- **Returns**: An observable of the HTTP response.
|
152
|
+
|
153
|
+
---
|
154
|
+
|
155
|
+
## π Why Use This Service?
|
156
|
+
|
157
|
+
- **Security First**: reCAPTCHA ensures that requests are coming from human users and helps prevent bot attacks.
|
158
|
+
- **Seamless Integration**: Automatically handles reCAPTCHA token inclusion for every HTTP request, so you donβt have to manage tokens manually.
|
159
|
+
- **Customizable**: Easily change header names and reCAPTCHA action types according to your needs.
|
160
|
+
- **Angular 17+ Compatible**: This package supports Angular version 17 and above, ensuring that your app stays up to date with the latest Angular features.
|
161
|
+
|
162
|
+
---
|
163
|
+
|
164
|
+
## π¨ Contributing
|
165
|
+
|
166
|
+
We welcome contributions from the community! If you have a bug fix, feature request, or improvement, please fork the repository and submit a pull request. Hereβs how:
|
167
|
+
|
168
|
+
1. Fork the repository.
|
169
|
+
2. Clone your fork and create a new branch (`git checkout -b feature-branch`).
|
170
|
+
3. Commit your changes (`git commit -am '[FEATURE] Add new feature'`).
|
171
|
+
4. Push to your branch (`git push origin feature-branch`).
|
172
|
+
5. Open a pull request with a detailed explanation of your changes.
|
173
|
+
|
174
|
+
---
|
175
|
+
|
176
|
+
## π License
|
177
|
+
|
178
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
179
|
+
|
180
|
+
---
|
181
|
+
|
182
|
+
## π¬ Get in Touch
|
183
|
+
|
184
|
+
For questions, support, or feedback, feel free to contact us at [asgarihope@gmail.com](mailto:asgarihope@gmail.com).
|
185
|
+
|
186
|
+
---
|
187
|
+
|
188
|
+
**Thank you for using `http-client-with-recaptcha`!** π
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "http-client-with-recaptcha",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.1",
|
4
4
|
"peerDependencies": {
|
5
5
|
"@angular/common": "^17.0.0",
|
6
6
|
"@angular/core": "^17.0.0"
|
@@ -35,4 +35,4 @@
|
|
35
35
|
"default": "./fesm2022/http-client-with-recaptcha.mjs"
|
36
36
|
}
|
37
37
|
}
|
38
|
-
}
|
38
|
+
}
|