Coinbase
Add the Coinbase authorization provider to Aura Auth to authenticate and authorize users
Coinbase
Set up the Coinbase authorization provider in your Aura Auth instance.
Coinbase OAuth App
Register the Application
The first step is to create and register an OAuth App on the Coinbase CDP Portal to obtain access to the user's resources.
-
Navigate to your Coinbase profile and go to API Keys > Secret API Keys.
-
Click Create API Key.
-
Fill in the "API Key nickname".
-
Register the API restrictions:
- IP allowlist:
localhost:3000(or your production domain when deploying)
- IP allowlist:
-
Set the Authorization callback URL to
http://localhost:3000/auth/callback/coinbase.- (Make sure to replace
localhost:3000with your production domain when deploying)
- (Make sure to replace
-
Click Register application.
-
Ensure you copy the Client ID and click Generate a new client secret.
Installation
Install the @aura-stack/auth package. Please follow the Installation Guide to complete the setup and core configuration for aura-stack/auth.
npm install @aura-stack/authEnvironment setup
Now, you must configure the environment variables required by Aura Auth, including the Coinbase credentials and the encryption secrets.
# Aura Secrets
AURA_AUTH_SECRET="your-32-byte-secret"
AURA_AUTH_SALT="your-32-byte-salt"
# Coinbase Credentials
AURA_AUTH_COINBASE_CLIENT_ID="your_coinbase_client_id"
AURA_AUTH_COINBASE_CLIENT_SECRET="your_coinbase_client_secret"Configure the Auth Instance
Configure the createAuth instance inside an auth.ts file located at the root of your project. Ensure you explicitly export the handlers, api, and jose objects.
import { createAuth } from "@aura-stack/auth"
export const auth = createAuth({
oauth: ["coinbase"],
})
// Extract the required utilities
export const { handlers, api, jose } = authThe handlers object contains mapping utilities for standard HTTP methods (GET, POST, PATCH) as well as a unified ALL
handler. This allows you to easily mount the authentication routes across any framework (Next.js, Elysia, Express, etc.).
Customizing the OAuth Provider
If you need to define custom scopes, change the response type, or map profile data differently, you can use the provider's factory function instead of a simple string identifier.
import { createAuth } from "@aura-stack/auth"
import { coinbase } from "@aura-stack/auth/oauth/coinbase"
export const auth = createAuth({
oauth: [
coinbase({
authorize: {
params: {
// Override default scopes
scope: "wallet:user:read wallet:user:email",
},
},
}),
],
})
export const { handlers, api, jose } = authSign In to Coinbase (Client & Server)
There are multiple ways to trigger the sign-in flow depending on your ecosystem.
Sign-in Path (Direct Navigation)
The common route to trigger the auth flow natively without needing a client library is simply navigating the browser to:
http://localhost:3000/auth/signIn/coinbase
Client-Side (React, Vue, etc.)
You can utilize the createAuthClient utility to programmatically trigger sign-ins. You can also define a redirectTo destination.
Constraint Rule: The baseURL passed into createAuthClient MUST exactly match the root domain and path where the HTTP
handlers expose their endpoints on the server.
import { createAuthClient } from "@aura-stack/auth/client"
export const authClient = createAuthClient({
baseURL: "http://localhost:3000/auth",
})
const triggerSignIn = async () => {
await authClient.signIn("coinbase", {
redirectTo: "/dashboard",
})
}Server-Side (Next.js Actions, Remix Loaders, etc.)
For environments supporting server-side actions, use the programmatic api.signIn method securely.
import { api } from "./auth"
export const serverSignIn = async () => {
const response = await api.signIn("coinbase", {
redirectTo: "http://localhost:3000/dashboard",
})
// Example returning redirect location
return response.headers.get("Location")
}Session Retrieval
After a user successfully signs in, you can retrieve their session data securely.
Client-Side:
const session = await authClient.getSession()
console.log(session?.user) // The authenticated Coinbase user profileServer-Side:
// Note: You must pass the native Web Request object or Headers!
const session = await api.getSession(request)
console.log(session?.user) // Safely retrieved backend session