OAuth Overview
OAuth is an open standard for authorization, which allows third-party services to securely access resources without exposing sensitive user credentials. NextAuth.js supports OAuth 2.0 and integrates with multiple authentication providers out of the box. Nile auth allows you to configure OAuth providers, all while handling the authentication flows and securely storing and managing user sessions directly in your database.Setting Up OAuth Providers
Authorization Code Flow
Your server acts as a proxy against Nile auth. A client interacts directly with your endpoints, which are forwarded on to Nile auth, which does all of the heavy lifting for you, all the while keeping it transparent to your users. When a user signs in via an OAuth provider, the following flow occurs:- The user clicks the login button for the desired provider (e.g., Google, GitHub).
- The user is redirected to the provider’s login page.
- The user grants permission to your application.
- The provider redirects the user back to your application with an authorization code.
- Your server then exchanges the authorization code for an access token from nile auth, which in turn sends a payload back to give to the client.
- The user is authenticated, and a session is created.
Provider Configuration
All providers can be configured on the Configuration screen under Providers, which is located in the Tenant and Users page
When using SSO providers and email + password, the
email_verified
column in the users.users
table must be set. An error will be produced if an SSO user attempts to log in with email + password.Error Handling
Because your backend service proxy’s Nile auth’s API, you can intercept errors for your users and handle them accordingly (vs using the default pages). In this example, a previously existing user has tried to log in with an email that already exists within the system, and it is tied to a different provider (eg the user used the same email in Google and Discord)Example error handling
/api/auth/error/route.tsx
/app/errors/oauth-not-linked.tsx