@skhashaev/steam-login
v1.0.0
Published
A lightweight library for Steam OpenID authentication, with adapter for Supabase Edge Functions.
Downloads
171
Maintainers
Readme
@skhashaev/steam-login
A lightweight TypeScript library for Steam OpenID authentication with adapters for different platforms.
Features
- 🔐 Simple Steam OpenID 2.0 authentication
- 🎯 Platform-specific adapters (Supabase Edge Functions, and more coming soon, if will be needed)
- 📦 TypeScript support with full type definitions
- 🚀 Easy to use API
- ✨ No dependencies on the core library
Installation
For Deno (Supabase Edge Functions)
import { SupabaseSteamAuth } from "npm:@skhashaev/steam-login";For Node.js
npm install @skhashaev/steam-loginTry the Demo
Want to see it in action? Clone the repository and run the demo:
git clone https://github.com/skhashaev/steam-login.git
cd steam-login
npm install
npm run demoThis will start a local server at http://localhost:3000 with a working Steam login example.
Quick Start
Using the Supabase Adapter
import { SupabaseSteamAuth } from "@skhashaev/steam-login";
const steamAuth = new SupabaseSteamAuth({
realm: "https://your-site.com",
returnUrl: "https://your-site.com/auth/callback",
});
// Handle the request automatically
const result = await steamAuth.handleRequest(req);
switch (result.type) {
case "redirect":
return result.response; // Redirects to Steam
case "success":
console.log(result.steamId); // User's Steam ID
break;
case "error":
console.error(result.error);
break;
}Using the Core Library
import { SteamAuth } from "@skhashaev/steam-login";
const steamAuth = new SteamAuth({
realm: "https://your-site.com",
returnUrl: "https://your-site.com/auth/callback",
});
// Get the redirect URL
const redirectUrl = steamAuth.getRedirectUrl();
// Verify the callback
const steamId = await steamAuth.verify(requestUrl);Platform Adapters
This library includes adapters for different platforms (currently only one) to make integration easier:
- Supabase Edge Functions - Full documentation for using with Supabase
More adapters coming soon! Contributions are welcome.
How It Works
This library implements the Steam OpenID 2.0 authentication flow:
- Redirect: User is redirected to Steam's login page
- Authentication: User logs in with their Steam account
- Callback: Steam redirects back to your site with authentication data
- Verification: The library verifies the response with Steam's servers
- Result: You receive the user's 64-bit Steam ID
Getting User Profile Data
The Steam ID alone doesn't contain profile information. To get the user's profile (avatar, name, etc.), you need to use the Steam Web API.
Using the Steam Web API directly
const STEAM_API_KEY = "your-api-key"; // Get from https://steamcommunity.com/dev/apikey
async function getUserProfile(steamId: string) {
const response = await fetch(
`http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=${STEAM_API_KEY}&steamids=${steamId}`
);
const data = await response.json();
return data.response.players[0];
}Using steamapi-ts (Recommended)
For a better developer experience with full TypeScript support and auto-generated types for all Steam Web API endpoints, check out my other library @skhashaev/steamapi-ts:
npm install @skhashaev/steamapi-tsimport { createSteamClient } from "@skhashaev/steamapi-ts";
import "dotenv/config";
const steam = createSteamClient(process.env.API_KEY!);
async function getUserProfile(steamId: string) {
// Call API methods with full type safety
const response = await steam.ISteamUser.GetPlayerSummaries_v2({
steamids: steamId,
});
const data = await response.json();
return data.response.players[0];
}API Reference
SteamAuth
Core class for Steam OpenID authentication.
Constructor Options
interface SteamAuthOptions {
realm: string; // Your site's base URL
returnUrl: string; // Where Steam redirects after login
}Methods
getRedirectUrl(): string- Returns the Steam login URLverify(requestUrl: string): Promise<string | null>- Verifies the callback and returns the Steam ID
SupabaseSteamAuth
Adapter for Supabase Edge Functions.
Methods
redirect(): Response- Returns a redirect Response to Steamverify(request: Request): Promise<string | null>- Verifies the callbackhandleRequest(request: Request): Promise<SteamAuthResult>- Automatically handles both redirect and verification
Contributing
Contributions are welcome! Feel free to:
- Add new platform adapters
- Report bugs
- Suggest features
- Improve documentation
License
ISC
