Getting Started

Anon Link for web uses an OAuth-style linking process to securely link end-user accounts to your application. This guide will walk you through the implementation of this process.

Generate a URL for your end-users to link their accounts:

Replace the following parameters:

ParameterDescription
APPThe app name you’re linking to (e.g., instagram)
APP_USER_IDThe ID of the user linking their account (e.g. user-id-123)
REDIRECT_URLThe URL to redirect the user back to after the linking process is complete (e.g. https://your.web.app/link/redirect)
YOUR_ANON_API_KEYYour Anon API key (e.g. anon_randomCombinationOfLetters&Numbers1234567890)
Use the API reference to learn about all parameters.

When a user wants to link one of their account to your web app, send them to Anon Link using the linkUrl from the previous step. For example, the end-user clicks a button in your app that generates the linkUrl and redirects them to Anon Link.

Here’s the end-to-end flow:

1

User Initiates Link

The end-user clicks a button in your app that generates the link URL, redirecting them to Anon’s OAuth dialog flow.

2

User Authorizes

The user confirms authorization for Anon to link their session for the specified app.

3

User Authenticates

The user enters their credentials directly into the app website’s login flow via popup.

4

Redirect

Once the user completes authentication, they are redirected to the redirect URL you registered in Step 1 with query parameters describing the link result.

3 - Handle the Redirect

After the session has been saved, the user is redirected back to your web app via the redirect URL. The redirect URL is called with several query parameters describing the result of the link process.

ParameterDescriptionValues
typeIndicates the result of the linking process'success'
'error'
error_codePresent only when type is 'error''bad_input'
'bad_authorization'
'anon_internal_error'
stateThe same state value provided in the initial request

A valid redirect URL with a successul link result will look like this:

https://your.web.app/link/redirect?type=success&state=123456

Handle the redirect in your application by checking the type parameter to determine the result of the linking process:

const urlParams: URLSearchParams = new URLSearchParams(window.location.search);
const type: string | null = urlParams.get('type');
const state: string | null = urlParams.get('state');

if (type === 'success') {
  // Linking was successful
  console.log('Session linked successfully');
  // Proceed with your application logic for a successful link
} else if (type === 'error') {
  // Linking failed
  const errorCode: string | null = urlParams.get('error_code');
  console.error('Linking failed with error:', errorCode);
  // Handle the error appropriately
}

console.log('State:', state);

At this point, the user’s session is linked. Your app can now automate actions on their behalf using the stored session.

Next Steps

If you encounter any issues or have questions, don’t hesitate to reach out to the Anon team at support@anon.com.