Authentication Guide

Secure your application with our authentication module that supports API keys, OAuth 2.0, and JWT.

Authentication Foundations

eJThB7's authentication module provides three layers of security:

1. Secure Communication

All authentication requests are encrypted with TLS 1.3 by default. Use the secure flag for all cookies.

2. Token Signing

We use HMAC with SHA-256 for JWT signing. Store your secret in environment variables, never hardcoded.

3. Rate Limiting

Built-in rate limiting to prevent brute-force attacks (50 requests per minute per IP).

const secureContext = createContext();
secureContext.useTLS = true;
secureContext.hstsMaxAge = 31536000;
secureContext.cookieOptions = {
    secure: true,
    httpOnly: true,
    sameSite: 'strict'
};
                                

API Keys

Sample API Key

Create API Key

Using API Key

const response = await fetch('https://api.ejthb7.example/endpoint', { method: 'GET', headers: { Authorization: 'Bearer ' + API_KEY } });

OAuth 2.0 Integration

Authorization Flow

  • 1

    Redirect user to authorization endpoint

    GET https://auth.ejthb7.com/oauth/authorize
  • 2

    User grants permission

    Ensure you implement proper consent screen with clear scope explanations
  • 3

    Receive authorization code

    POST https://api.ejthb7.com/oauth/token

Example OAuth Implementation

JSON Web Tokens (JWT)

JWT Claims

Standard claims (RFC 7519)
Claim Value Type Description
iss string Issuer
exp number Expiration timestamp
iat number Issued at timestamp
Ensure you set appropriate expiration (24h max) and always use HTTPS.

Token Validation

Always validate the following:

  • Signature validity
  • Issuer matches expected value
  • Expiration time
  • Nonce if required
// Sample validation pattern

if (Date.now() > jwt.exp * 1000) {
  throw new Error('Token expired');
}

if (jwt.iss !== 'https://auth.ejthb7.com') {
  throw new Error('Invalid issuer');
}

verifySignature(jwt, secretKey); // This should fail if key is invalid
                                            

Security Best Practices

Key Management

  • 🔒 Rotate API keys every 90 days via /apikeys/rotate
  • 🔑 Use environment variables never hardcoded values
  • 🔄 Implement automatic key rotation for production systems

Transport Security

Always use HTTPS
Mandatory TLS 1.3
HSTS headers for session security

Security Warning

Never store sensitive credentials in logs or browser storage. Always sanitize error responses to prevent information leakage.

```