@meridianjs/google-oauth 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# @meridianjs/google-oauth
|
|
2
|
+
|
|
3
|
+
Google OAuth 2.0 module for MeridianJS. Adds `GET /auth/google` and `GET /auth/google/callback` routes that authenticate users via Google, then issue a MeridianJS JWT.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @meridianjs/google-oauth
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Configuration
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
// meridian.config.ts
|
|
15
|
+
export default defineConfig({
|
|
16
|
+
modules: [
|
|
17
|
+
{
|
|
18
|
+
resolve: "@meridianjs/google-oauth",
|
|
19
|
+
options: {
|
|
20
|
+
clientId: process.env.GOOGLE_CLIENT_ID ?? "",
|
|
21
|
+
clientSecret: process.env.GOOGLE_CLIENT_SECRET ?? "",
|
|
22
|
+
callbackUrl: process.env.GOOGLE_REDIRECT_URI ?? "",
|
|
23
|
+
frontendUrl: process.env.APP_URL,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
})
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Add to your `.env`:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
|
|
34
|
+
GOOGLE_CLIENT_SECRET=your-client-secret
|
|
35
|
+
GOOGLE_REDIRECT_URI=http://localhost:9000/auth/google/callback
|
|
36
|
+
APP_URL=http://localhost:5174
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`GOOGLE_REDIRECT_URI` must also be registered as an **Authorised redirect URI** in the [Google Cloud Console](https://console.cloud.google.com/) for your OAuth 2.0 client.
|
|
40
|
+
|
|
41
|
+
## How It Works
|
|
42
|
+
|
|
43
|
+
1. User visits `GET /auth/google` → redirected to Google consent screen.
|
|
44
|
+
2. After consent, Google redirects to `GOOGLE_REDIRECT_URI`.
|
|
45
|
+
3. The framework exchanges the code for a Google profile.
|
|
46
|
+
4. If a user with the matching Google ID exists, they are logged in. Otherwise, a new account is created using the Google profile data.
|
|
47
|
+
5. If the callback URL included an `invite` query parameter, the user is automatically added to the invited workspace.
|
|
48
|
+
6. A MeridianJS JWT is issued and the user is redirected to `APP_URL` with the token in the query string.
|
|
49
|
+
|
|
50
|
+
## Production
|
|
51
|
+
|
|
52
|
+
In production, update your `.env` with the public URLs:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
GOOGLE_REDIRECT_URI=https://api.yourdomain.com/auth/google/callback
|
|
56
|
+
APP_URL=https://app.yourdomain.com
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
And update the authorised redirect URIs in the Google Cloud Console to match.
|
|
60
|
+
|
|
61
|
+
## License
|
|
62
|
+
|
|
63
|
+
MIT
|