Understanding the provider architecture in @warpy-auth-sdk/core.
Providers in @warpy-auth-sdk/core are factory functions that return configuration objects for different authentication methods. They abstract the complexity of OAuth flows, email magic links, and other authentication mechanisms into simple, reusable functions.
The provider system is designed to be:
@warpy-auth-sdk/core comes with several built-in providers:
All OAuth providers use PKCE by default with the S256 method and secure HttpOnly cookie storage for verifiers. You can override via pkce option: "S256" | "plain" | false.
/user/emailsdomain optiontenantidentify and email scopesClient-Id header for user APIAll providers implement a common interface:
Base type for all authentication providers
type Provider = OAuthProvider | EmailProvider | CustomProviderConfiguration for OAuth 2.0 providers
interface OAuthProvider {
type: 'oauth';
clientId: string;
clientSecret: string;
authorizeUrl: string;
tokenUrl: string;
userInfoUrl: string;
scope?: string[];
getUser: (token: string) => Promise<User>;
}Configuration for email magic link providers
interface EmailProvider {
type: 'email';
server: string;
from: string;
auth?: {
user: string;
pass: string;
};
sendMagicLink: (email: string, token: string) => Promise<void>;
verifyToken: (token: string) => Promise<boolean>;
}Providers are used in your authentication configuration:
import { google, email } from '@warpy-auth-sdk/core';
// Google OAuth provider
const googleProvider = google({
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
redirectUri: process.env.GOOGLE_REDIRECT_URI!,
});
// Email magic link provider
const emailProvider = email({
server: 'smtp.gmail.com:587',
from: 'noreply@yourdomain.com',
auth: {
user: process.env.SMTP_USER!,
pass: process.env.SMTP_PASS!,
},
});
// Use in authentication config
const authConfig = {
secret: process.env.AUTH_SECRET!,
provider: googleProvider, // or emailProvider
};Understanding how providers work in the authentication flow:
You can create custom providers for any OAuth 2.0 or custom authentication system:
import { OAuthProvider } from '@warpy-auth-sdk/core';
function customOAuth(options: {
clientId: string;
clientSecret: string;
redirectUri: string;
authorizeUrl: string;
tokenUrl: string;
userInfoUrl: string;
scope?: string[];
}): OAuthProvider {
return {
type: 'oauth',
...options,
async getUser(token: string) {
const response = await fetch(options.userInfoUrl, {
headers: {
Authorization: `Bearer ${token}`,
},
});
const user = await response.json();
return {
id: user.id,
email: user.email,
name: user.name,
picture: user.avatar_url,
};
},
};
}
// Use your custom provider
const customProvider = customOAuth({
clientId: process.env.CUSTOM_CLIENT_ID!,
clientSecret: process.env.CUSTOM_CLIENT_SECRET!,
redirectUri: process.env.CUSTOM_REDIRECT_URI!,
authorizeUrl: 'https://api.custom.com/oauth/authorize',
tokenUrl: 'https://api.custom.com/oauth/token',
userInfoUrl: 'https://api.custom.com/user',
scope: ['read', 'write'],
});Each provider has specific configuration requirements:
Security considerations for providers:
Now that you understand the provider architecture, you can explore specific providers: