Skip to content

Commit 1845030

Browse files
committed
oauth2 fixes
1 parent 1cac6b0 commit 1845030

File tree

2 files changed

+55
-18
lines changed

2 files changed

+55
-18
lines changed

adminforth/documentation/docs/tutorial/05-Plugins/11-oauth.md

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# OAuth Authentication
22

3-
The OAuth plugin enables OAuth2-based authentication in AdminForth, allowing users to sign in using their Google, GitHub, or other OAuth2 provider accounts.
3+
The OAuth plugin enables OAuth2-based authentication in AdminForth, allowing users to sign in using their Google, GitHub, Facebook or other OAuth2 provider accounts.
44

55
## Installation
66

@@ -9,16 +9,16 @@ To install the plugin:
99
```bash
1010
npm install @adminforth/oauth --save
1111
npm install @adminforth/google-oauth-adapter --save # for Google OAuth
12-
npm install @adminforth/facebook-oauth-adapter --save # for Facebook OAuth
1312
```
1413

1514
## Configuration
1615

17-
### 1. OAuth Provider Setup
16+
This section provides a step-by-step guide to configure the OAuth plugin for Google authentication. See [OAuth2 Providers](#oauth2-providers) for other providers.
17+
18+
### 1. OAuth Provider Setup (Google Example)
1819

1920
You need to get the client ID and client secret from your OAuth2 provider.
2021

21-
#### For Google:
2222
1. Go to the [Google Cloud Console](https://console.cloud.google.com) and log in.
2323
2. Create a new project or select an existing one
2424
3. Go to `APIs & Services``Credentials`
@@ -33,19 +33,6 @@ GOOGLE_OAUTH_CLIENT_ID=your_google_client_id
3333
GOOGLE_OAUTH_CLIENT_SECRET=your_google_client_secret
3434
```
3535

36-
#### For Facebook:
37-
1. Go to the [Facebook Developers](https://developers.facebook.com/)
38-
2. Go to `My apps`
39-
3. Create a new project or select an existing one (choose Authenticate and request data from users with Facebook Login)
40-
4. Go to `Use Cases` - `Authenticate and request data from users with Facebook Login` -> `Customize` and add email permissions
41-
5. Go to `App Settings` -> `Basic`
42-
6. Get App ID and App secret
43-
7. Add the credentials to your `.env` file:
44-
45-
```bash
46-
FACEBOOK_OAUTH_CLIENT_ID=your_facebook_client_id
47-
FACEBOOK_OAUTH_CLIENT_SECRET=your_facebook_client_secret
48-
```
4936

5037
### 2. Plugin Configuration
5138

@@ -143,5 +130,55 @@ new OAuthPlugin({
143130
```
144131

145132

133+
## OAuth2 Providers
134+
135+
136+
### Facebook Adapter
137+
138+
Install Adapter:
139+
140+
```
141+
npm install @adminforth/facebook-oauth-adapter --save
142+
```
143+
144+
145+
1. Go to the [Facebook Developers](https://developers.facebook.com/)
146+
2. Go to `My apps`
147+
3. Create a new project or select an existing one (choose Authenticate and request data from users with Facebook Login)
148+
4. Go to `Use Cases` - `Authenticate and request data from users with Facebook Login` -> `Customize` and add email permissions
149+
5. Go to `App Settings` -> `Basic`
150+
6. Get App ID and App secret
151+
7. Add the credentials to your `.env` file:
152+
153+
```bash
154+
FACEBOOK_OAUTH_CLIENT_ID=your_facebook_client_id
155+
FACEBOOK_OAUTH_CLIENT_SECRET=your_facebook_client_secret
156+
```
157+
158+
Add the adapter to your plugin configuration:
159+
160+
```typescript title="./resources/adminuser.ts"
161+
import AdminForthAdapterFacebookOauth2 from '@adminforth/facebook-oauth-adapter';
162+
163+
// ... existing resource configuration ...
164+
plugins: [
165+
new OAuthPlugin({
166+
adapters: [
167+
...
168+
new AdminForthAdapterFacebookOauth2({
169+
clientID: process.env.FACEBOOK_OAUTH_CLIENT_ID,
170+
clientSecret: process.env.FACEBOOK_OAUTH_CLIENT_SECRET,
171+
}),
172+
],
173+
}),
174+
]
175+
```
176+
177+
178+
### Need custom provider?
179+
180+
Just fork any existing adapter e.g. [Google](https://github.com/devforth/adminforth-google-oauth-adapter) and adjust it to your needs.
146181

182+
This is really easy, you have to change several then 10 lines of code in this [file](https://github.com/devforth/adminforth-google-oauth-adapter/blob/main/index.ts)
147183

184+
Then just publish it to npm and install it in your project.

dev-demo/inventory.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services:
66
ports:
77
- '8124:8123'
88
- '9001:9000'
9-
image: clickhouse/clickhouse-server
9+
image: clickhouse/clickhouse-server:24.12
1010
restart: always
1111
environment:
1212
CLICKHOUSE_USER: demo

0 commit comments

Comments
 (0)