Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/raresail/nest-oauth2-micro-service
A template for an authentication service using oAuth2
https://github.com/raresail/nest-oauth2-micro-service
google-oauth2 microservice nestjs oauth2 template
Last synced: 14 days ago
JSON representation
A template for an authentication service using oAuth2
- Host: GitHub
- URL: https://github.com/raresail/nest-oauth2-micro-service
- Owner: RaresAil
- Created: 2021-07-17T11:40:44.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-03-08T02:10:31.000Z (over 1 year ago)
- Last Synced: 2024-10-04T16:41:44.512Z (about 1 month ago)
- Topics: google-oauth2, microservice, nestjs, oauth2, template
- Language: TypeScript
- Homepage:
- Size: 1.38 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NestJS OAuth2 Service
### Table of Contents
1. [Add new provider](#add-new-provider)
2. [ENV File](#env-file)
3. [How to generate the RSA Key](#how-to-generate-the-rsa-key)### Add new provider
1. Define the provider in `providers` constant located in `src/providers/constants.ts`
2. Create a directory in `src/providers` with the name defined in `providers`. e.g. if in providers you have `Facebook: 'facebook-provider'` the directory name will be `facebook-provider`
3. In the directory, you should have 2 files.
- `config.ts` - should default export 2 keys:
- `redirectPath` - With this exact name
- `callbackPath` - With this exact name
- `strategy.ts` - should default export the Strategy class, check the google example.
4. In the `auth.controller.ts` define the 2 routes and assign the `@AuthMethod` attribute with the provider and method. e.g.```ts
@AuthMethod(providers.Google, methods.Callback)
public authWithGoogle() {
throw new InternalServerErrorException();
}@AuthMethod(providers.Google, methods.Authorize)
public loginWithGoogle() {
throw new InternalServerErrorException();
}
```### ENV File
| Key | Value |
| -------------------- | ---------------------------------------------------- |
| GOOGLE_CLIENT_ID | \ |
| GOOGLE_CLIENT_SECRET | \ |
| LOGIN_ROUTE | /login |
| HOME_ROUTE | / |
| UUID_NAMESPACE | \ (It can be an uuidV4 generated) |
| JWT_PRIVATE_KEY | \ |
| JWT_PUBLIC_KEY | \ |
| DATABASE_URL | postgresql://user:pass@host:port/db?schema=schema |
| PROXY_IP | \ (The ip for the proxy) (OPTIONAL) |For `PROXY_IP`, it has to be the ip for the proxy that the app is used from,
e.g. `127.0.0.1` for a local proxy.### How to generate the RSA Key
1. Generate the private key:
```bash
openssl genrsa -out private.key 3072
```2. Extract the public key
```bash
openssl rsa -in private.pem -pubout -out public.pem
```3. When saving the key in .env, remove the EOL (keep the key in a single line) and remove the prefix/suffix.
- The prefixes are
- -----BEGIN RSA PRIVATE KEY-----
- -----BEGIN PUBLIC KEY-----
- The suffixes are
- -----END RSA PRIVATE KEY-----
- -----END PUBLIC KEY-----