authjs-steam-provider
v1.0.0
Published
Steam OpenID provider for Auth.js v5 (NextAuth), edge-ready and typed.
Downloads
17
Maintainers
Readme
authjs-steam-provider
Auth.js v5 provider for Steam OpenID. Minimal, edge-friendly, and typed. It plugs directly into NextAuth/Auth.js and exchanges the Steam OpenID assertion for a session, then enriches the profile via Steam Web API.
• Provider ID: steam
• Peer deps: next (>=13 <16), next-auth (>=5.0.0-beta.18 <6)
Installation
npm install authjs-steam-provider
# or
yarn add authjs-steam-providerYou also need a Steam Web API Key. Get it at: https://steamcommunity.com/dev/apikey
Requirements and Configuration
Set the following environment variables:
- NEXTAUTH_URL: Your public app URL (e.g. https://example.com)
- STEAM_API_KEY: Your Steam Web API key
Provider options (required):
clientSecret: The Steam Web API keycallbackUrl: Absolute callback base URL for your NextAuth callback route, e.g.${NEXTAUTH_URL}/api/auth/callback
Notes:
- The provider constructs
openid.return_toas${callbackUrl}/steamand validates the OpenID assertion against it. - Works on the Edge runtime (no Node-specific APIs).
Usage (Next.js App Router, Auth.js v5)
File: app/api/auth/[...nextauth]/route.ts
import NextAuth from "next-auth"
import SteamProvider from "authjs-steam-provider"
export const { handlers, auth } = NextAuth({
providers: [
// Important: pass the Request to the provider
(req) =>
SteamProvider(req, {
clientSecret: process.env.STEAM_API_KEY!,
callbackUrl: `${process.env.NEXTAUTH_URL}/api/auth/callback`,
}),
],
})
export const GET = handlers.GET
export const POST = handlers.POSTClient-side sign-in:
import { signIn } from "next-auth/react"
// triggers the Steam OpenID flow
await signIn("steam")Accessing the session:
import { auth } from "@/app/api/auth/[...nextauth]/route"
export default async function Page() {
const session = await auth()
// session.user has id, name, email (synthetic), image
return <pre>{JSON.stringify(session, null, 2)}</pre>
}API Reference
Default export
SteamProvider(req: Request, options: SteamProviderOptions): OAuthConfig<SteamProfile>req: The Next.js Request of the current auth route handler.options:clientSecret: string— Steam Web API key.callbackUrl: string | URL— Base callback URL (e.g.${NEXTAUTH_URL}/api/auth/callback).- You may also pass standard
OAuthUserConfig<SteamProfile>fields viaoptions(as it extends Partial of it), if needed.
Profile mapping
profile(profile: SteamProfile) returns:
{
id: profile.steamid,
image: profile.avatarfull,
email: `${profile.steamid}@steamcommunity.com`, // synthetic (Auth.js requires an email)
name: profile.personaname,
}Authorization flow
- Initiates OpenID via
https://steamcommunity.com/openid/login. - Validates assertion server-side with
openid.mode=check_authentication. - Extracts
steamIdfrom the claimed identifier. - Fetches player summary using
ISteamUser/GetPlayerSummarieswithclientSecretandsteamId.
Types
SteamProviderOptions (from src/types/steam.ts):
interface SteamProviderOptions {
callbackUrl: string | URL
clientSecret: string
}SteamProfile is compatible with Steam Web API player summary, including at least:
interface SteamProfile {
steamid: string
personaname: string
avatar: string
avatarmedium: string
avatarfull: string
profileurl: string
// …additional fields from Steam
}Provider constants:
PROVIDER_ID = "steam"PROVIDER_NAME = "Steam"AUTHORIZATION_URL = "https://steamcommunity.com/openid/login"
Best Practices and Tips
- Ensure
NEXTAUTH_URLmatches your deployed domain (including protocol). callbackUrlmust be absolute and point to your NextAuth callback base:${NEXTAUTH_URL}/api/auth/callback.- Use a dedicated environment variable for
STEAM_API_KEY; never commit it. - If you customize session callbacks, keep the
user.idsourced fromprofile.steamidto maintain stable identity. - The email is synthetic to satisfy Auth.js serialization; don’t use it for outbound email.
- Prefer running the auth route on Edge for lower latency; this provider is edge-safe.
- Handle errors gracefully in UI; Steam may return non-OK responses if the user is private or API is down.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Links
- Auth.js Docs (v5): https://authjs.dev
- Issues / Contributing: https://github.com/goncalojbsousa/authjs-steam-provider/issues
