Custom Authentication

Learn how to integrate a full authentication flow within your application.


To allow users to authenticate their accounts from within your application, the steps will vary depending on the authentication flow used by the provider:

  • Credentials Flow : The provider accepts a set of credentials—such as a username and password, tokens, or connection parameters. During this process, the provider may also require the user to solve additional challenges like Two-Factor Authentication (2FA), One-Time Passwords (OTP), CAPTCHAs, or in-app validations.
  • QR Code Flow : The provider returns a QR code that must be displayed to the user. Your application should wait until the code is scanned and the authentication is completed. Each QR code have a short living time and must be refreshed when expired.
  • OAuth Flow: The provider uses a standard OAuth process, which involves redirecting the user to a login and consent screen. Once the user grants permission, they are redirected back to your application.

👍

Full example project on Github

Explore a complete example project used to support this guide on GitHub:https://github.com/unipile/unipile-auth-example


Here is what flow is used by each Provider. Follow the guide accordingly.

ProviderFlow
LinkedInCredentials Flow
IMAPCredentials Flow
InstagramCredentials Flow
WhatsAppQR Code Flow
TelegramQR Code Flow
GoogleOAuth Flow
Microsoft OutlookOAuth Flow


Configure proxy & location

When starting a Custom Authentication flow, you can provide a custom proxy or choose the location of the automatic proxy in the config field of the Start Auth Intent request. Unlike Hosted Authentication, the provider is already specified by the provider field, so the configuration does not need to be nested under a provider name.

  • config.custom_proxy specifies a proxy to use for the account. It takes precedence over any automatic proxy.
  • config.auto_proxy_config specifies the country of the automatic proxy, either directly with country or by inferring it from ip. When using ip, provide the end user's public IP address, not the IP address of your application server. Automatic proxy protection currently applies to LinkedIn, WhatsApp, and Instagram.

For example, start a LinkedIn authentication intent through a custom proxy:

const response = await customAuthApi.startAuthIntent({
  body: {
    provider: "linkedin",
    credentials: {
      username: "username",
      password: "password",
    },
    config: {
      custom_proxy: {
        host: "1.1.1.1",
        port: 5100,
        protocol: "https",
      },
    },
  },
});
curl --request POST \
     --url https://api.unipile.com/v2/auth/intent \
     --header 'X-API-KEY: api-key' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
  "provider": "linkedin",
  "credentials": {
    "username": "username",
    "password": "password"
  },
  "config": {
    "custom_proxy": {
      "host": "1.1.1.1",
      "port": 5100,
      "protocol": "https"
    }
  }
}
'

To use automatic proxy protection in a specific location instead, omit custom_proxy and pass an ISO 3166-1 alpha-2 country code, for example config.auto_proxy_config.country = "FR".

📘

For more details on custom proxies, automatic proxies, and the lookup order used to determine which proxy is applied, see our Proxy guide.


Did this page help you?