Overview

This guide explains how to use Snag’s social integration API to let your users connect their social accounts to their Snag profile. After creating a user in Snag (as explained in Managing User Accounts), you can use the social authentication endpoints to connect various social platforms to that user’s profile.

Supported Social Platforms

Snag supports connecting the following social platforms:

  • Twitter
  • Discord
  • Telegram
  • Epic Games
  • Steam

Connecting a Social Account

Endpoint

GET /api/{authType}/auth

Where {authType} is one of: twitter, discord, telegram, epic, or steam.

Query Parameters

ParameterTypeRequiredDescription
userIdUUIDYesThe ID of the user received from the user creation endpoint
websiteIdUUIDNoThe ID of the website (if applicable)
redirectStringYesThe URL where the user will be redirected after completing authentication
responseTypeStringNoThe type of response to return (redirect or json). Defaults to redirect

Example Request

GET /api/twitter/auth?userId=123e4567-e89b-12d3-a456-426614174001&redirect=https://your-app.com/auth-callback

Authentication Flow

  1. Call the /api/{authType}/auth endpoint with the required parameters
  2. The API will return a URL that you should redirect your user to
  3. The user will authenticate with the social platform and grant permissions
  4. After successful authentication, the user will be redirected to the URL specified in the redirect parameter
  5. The social account is now connected to the user’s Snag profile

Example Implementation

// Server-side implementation (e.g., in Node.js/Express)
app.get('/connect-twitter', async (req, res) => {
  const userId = req.query.userId; // Get from authenticated session
  
  try {
    const response = await fetch(
      `https://api.snagsolutions.io/api/twitter/auth?userId=${userId}&redirect=https://your-app.com/auth-callback`,
      {
        headers: {
          'Authorization': `Bearer ${process.env.SNAG_API_KEY}` // API key stored securely on server
        }
      }
    );
    
    const data = await response.json();
    
    // Redirect the user to the authentication URL
    res.redirect(data.url);
  } catch (error) {
    console.error('Error connecting Twitter account:', error);
    res.status(500).send('Error connecting Twitter account');
  }
});

// Client-side code to initiate the flow
function connectTwitterAccount(userId) {
  // Redirect to your server endpoint
  window.location.href = `/connect-twitter?userId=${userId}`;
}

Response Handling

Success Response (200 OK)

{
  "url": "https://auth-provider.com/oauth/authorize?client_id=xxx&redirect_uri=xxx&state=xxx"
}

The url property contains the authentication URL that you should redirect your user to.

Custom OAuth Applications

Snag allows you to use your own OAuth applications for Twitter, Discord, Epic Games, and Steam integrations. This enables you to maintain your brand identity throughout the authentication flow and have more control over the user experience.

If you would like to use your own client ID and client secret for any of these platforms, please contact the Snag team for integration support. We’ll guide you through the process of setting up and configuring your custom OAuth applications with our system.

Next Steps

After connecting social accounts, you can use this information to enhance the user experience in your application and leverage it for loyalty program features.