Sub-User Magic Link Authentication

Overview

The Magic Link Authentication API enables platform partners to generate secure, passwordless authentication links for their sub-users. These magic links allow sub-users to access Logfire features through your platform without requiring separate password credentials.

Key Benefits

  • Passwordless authentication
  • Time-limited access links
  • Secure sub-user verification
  • Seamless integration with partner platforms

API Endpoint

POST https://api.logfire.ai/api/auth/user-magiclink

Request Headers

Content-Type: application/json

Request Body

{
    "externalId": "subuser_partner_id",        // Your unique identifier for the sub-user on partner's platform
    "profileId": "subuser_logfire_id"           // Unique identifier for the sub-user on logfire
}

Required Fields

FieldTypeDescription
externalIdstringYour unique identifier for the sub-user on partner’s platform
profileIduuidUnique identifier for the sub-user on logfire

Success Response (202 Accepted)

{
    "isSuccessful": true,
    "magicLinkId": "unique_token_string",
    "expiryTime": "2024-03-21T10:00:00Z"
}

Response Fields

FieldTypeDescription
isSuccessfulbooleanIndicates if the request was successful
magicLinkIdstringUnique token for magic link authentication
expiryTimestringISO 8601 datetime when the magic link expires

Error Responses

400 Bad Request

{
    "isSuccessful": false,
    "message": ["find sub-user : {error details}"]
}

500 Internal Server Error

{
    "message": "Internal Server Error"
}

Usage Guidelines

Authentication Flow

  1. Partner generates magic link for sub-user
  2. Follow instruction for Iframe Integration and use the magic link id to authenticate the sub-user

Security Considerations

  • Magic links expire after a set time period
  • Links are single-use only
  • Sub-user validation occurs before link generation
  • Access is limited to sub-user’s specific resources

Best Practices

  1. Link Generation

    • Generate links only when needed
    • Verify sub-user exists before requesting link
    • Handle expired links appropriately
  2. Error Handling

    • Implement proper error handling for all responses
    • Provide clear feedback to sub-users
    • Log authentication attempts for security monitoring
  3. Rate Limiting

    • Implement reasonable request limits
    • Handle rate limit errors gracefully
    • Consider implementing backoff strategies

Common Issues and Solutions

Invalid Sub-User

  • Issue: 400 Bad Request with “find sub-user” error
  • Solution: Verify external ID exists and is correctly mapped

Service Unavailable

  • Issue: 500 Internal Server Error
  • Solution: Retry request after brief delay

Expired Links

  • Issue: Link no longer valid
  • Solution: Generate new magic link

Implementation Example

async function generateMagicLink(subUser) {
    try {
        const response = await fetch('https://api.logfire.ai/api/auth/user-magiclink', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                externalId: 'partner_user_id',
                profileId: subUser.profileId
            })
        });
        
        const data = await response.json();
        if (!data.isSuccessful) {
            throw new Error(data.message);
        }
        
        return data;
    } catch (error) {
        console.error('Magic link generation failed:', error);
        throw error;
    }
}