API Authentication

Learn how to authenticate with the PhishFortress API using API keys and OAuth 2.0

Authentication Overview

PhishFortress API supports two authentication methods: API Keys for server-to-server communication and OAuth 2.0 for user-facing applications. All API requests must be authenticated to ensure security and proper access control.

API Key Authentication

API keys are the recommended method for server-to-server integrations and automated scripts.

Generating an API Key

  1. Log in to your PhishFortress dashboard
  2. Navigate to Settings → API Keys
  3. Click "Generate New API Key"
  4. Provide a descriptive name for the key
  5. Select the appropriate permissions/scopes
  6. Copy and securely store the generated key

OAuth 2.0 Authentication

OAuth 2.0 is recommended for user-facing applications that need to access PhishFortress on behalf of users.

OAuth 2.0 Flow
Authorization Code Grant flow for web applications
  1. Authorization Request: Redirect user to PhishFortress authorization server
  2. User Consent: User logs in and grants permissions to your application
  3. Authorization Code: PhishFortress redirects back with authorization code
  4. Token Exchange: Exchange authorization code for access token
  5. API Access: Use access token to make authenticated API requests

OAuth Endpoints

Authorization: https://auth.phishfortress.com/oauth/authorize
Token: https://auth.phishfortress.com/oauth/token
Application Registration
Register your application to get OAuth credentials
  1. Go to Settings → OAuth Applications in your PhishFortress dashboard
  2. Click "Create New Application"
  3. Provide application name and description
  4. Set redirect URIs for your application
  5. Select required scopes/permissions
  6. Save and note the Client ID and Client Secret

Code Examples

Here are examples of how to authenticate with the PhishFortress API in different programming languages.

JavaScript/Node.js

const axios = require('axios');

const apiKey = 'your_api_key_here';
const baseURL = 'https://api.phishfortress.com/v1';

const client = axios.create({
  baseURL,
  headers: {
    'Authorization': `Bearer ${apiKey}`,
    'Content-Type': 'application/json'
  }
});

// Example: Get all campaigns
async function getCampaigns() {
  try {
    const response = await client.get('/campaigns');
    console.log(response.data);
  } catch (error) {
    console.error('Error:', error.response.data);
  }
}

Error Handling

The PhishFortress API uses standard HTTP status codes to indicate the success or failure of requests.

Status CodeDescriptionCommon Causes
200OKRequest successful
401UnauthorizedInvalid or missing API key
403ForbiddenInsufficient permissions
404Not FoundResource doesn't exist
429Too Many RequestsRate limit exceeded
500Internal Server ErrorServer-side issue
Error Response Format
{
  "error": {
    "code": "INVALID_API_KEY",
    "message": "The provided API key is invalid or has expired",
    "details": {
      "timestamp": "2024-01-15T10:30:00Z",
      "request_id": "req_abc123"
    }
  }
}

Testing Your Authentication

Use this simple endpoint to verify that your authentication is working correctly.

Authentication Test Endpoint

Test Request

GET https://api.phishfortress.com/v1/auth/verify

Expected Response

{
  "authenticated": true,
  "user": {
    "id": "user_123",
    "email": "admin@company.com",
    "organization": "Acme Corp"
  },
  "permissions": ["campaigns:read", "campaigns:write", "users:read"]
}