Nest Oauth2 Micro Service

screenshot of Nest Oauth2 Micro Service

A template for an authentication service using oAuth2

Overview

The NestJS OAuth2 Service is a service that allows developers to easily implement OAuth2 authentication in their NestJS applications. This service provides an efficient and secure way to authenticate users using popular providers like Google, Facebook, etc. The service handles the generation and management of RSA keys for secure token generation, as well as the configuration of the providers.

Features

  • Easily add new OAuth2 providers such as Google, Facebook, etc.
  • Securely manage RSA keys for token generation.
  • Configure provider settings in a centralized location.
  • Simplify authentication process using decorators and attributes.

ENV File

To configure the NestJS OAuth2 Service, modify the .env file with the following key-value pairs:

  • GOOGLE_CLIENT_ID: Your Google Client ID.
  • GOOGLE_CLIENT_SECRET: Your Google Client Secret.
  • LOGIN_ROUTE: The login route.
  • HOME_ROUTE: The home route.
  • UUID_NAMESPACE: The UUID namespace.
  • JWT_PRIVATE_KEY: Your RSA private key.
  • JWT_PUBLIC_KEY: Your RSA public key.
  • DATABASE_URL: The URL for the PostgreSQL database.
  • PROXY_IP: The IP address for the proxy (optional).

How to generate the RSA Key

To generate the RSA key for token generation, follow these steps:

  1. Generate the private key.
  2. Extract the public key.
  3. Remove the EOL (end of line) characters when saving the key in the .env file.
  4. Remove the prefixes and suffixes in the key.
    • Prefixes: -----BEGIN RSA PRIVATE KEY-----, -----BEGIN PUBLIC KEY-----
    • Suffixes: -----END RSA PRIVATE KEY-----, -----END PUBLIC KEY-----

Summary

The NestJS OAuth2 Service provides a seamless way for NestJS developers to implement OAuth2 authentication in their applications. With features like easy addition of providers, secure RSA key management, and centralized configuration, this service simplifies the authentication process. By following the installation and key generation steps, developers can quickly integrate OAuth2 authentication into their NestJS projects.