Auth SDK Redirect

1. Configure your Auth SDK URL

  • First you need to get your Temporary Token. After you have it append the URL parameter api_key=${TEMPORARY_TOKEN} to your authentication link.
  • Another mandatory parameter is externalUserId which is the ID of the user in your system. This is used to identify the user in the Finsquid system. It should be a unique string.
  • And finally add the redirect parameter to your Auth SDK LINK. This is the URL where the Auth SDK will redirect the user to after authentication. Here you should handle the response.
const AUTH_URL = new URL("https://sdk-staging.finsquid.io/auth");
AUTH_URL.searchParams.set("api_key", TEMPORARY_TOKEN);
AUTH_URL.searchParams.set("externalUserId", USER_ID);
AUTH_URL.searchParams.set("redirect", REDIRECT_URL);

const AUTH_LINK = AUTH_URL.toString();

Add the authentication link to your App with a navigation link (or similar):.

<a href="{AUTH_LINK}">Connect your bank</a>

2. Additional params (Optional)

  • You can specify the exact bank to connect to by passing the providerId parameter. To obtain the required provider ID, you should use the GET v1/providers endpoint. The request must be authenticated using your temporary token.
    curl -X GET 'https://gateway-staging.finsquid.io/v1/providers' \
    -H 'Authorization: Bearer {TEMPORARY_TOKEN}'
    

    You will receive a list of providers with IDs, and you can pass the required provider ID to the Auth SDK link.

    AUTH_URL.searchParams.set("providerId", "99");
    
  • You can also pass the credentials for the bank you want to connect to by passing the loginOptions parameter. The value of the parameter should be a JSON string with the following format:
    const loginOptions: SDKLoginOptions = [
      {
        loginMethod: "bankidSSN",
        userId: "098709870987",
      },
      {
        loginMethod: "usernamePassword",
        username: "098709870987",
        password: "password",
      },
    ];
    AUTH_URL.searchParams.set("loginOptions", JSON.stringify(loginOptions));
    

    In this case, every bank that utilizes the following login methods will have these values prepopulated.

3. Handle responses from Auth SDK

The response will be delivered by navigating to the specified redirect uri in the Auth SDK URL.

This redirect can be:

  • a redirect back to your web app where you process the response and asynchronously communicate with your backend service
  • a universal link, app link or deep link to your mobile app where you process the response and asynchronously communicate with your backend service
  • alternatively an API endpoint to your backend service where you process the response and redirect back to your application

Example

const params = new URLSearchParams(window.location.search);

const error = params.get("error");
if (error) {
  // Handle error response from Auth SDK
  console.log(
    `Auth SDK returned with error type: ${error} and error message: ${params.get("message")}.`
  );
} else {
  const data = JSON.parse(decodeURIComponent(params.get("data")));
  // This is the provider object that contains sid that should be used in headers for API requests
  console.log(`Auth SDK returned with provider object: ${data}`);
}

4. Authenticate and see if it works

After successful authentication you will receive the provider object inside data in the search params of the redirect URL.

{
  //You should use this sid in headers for API requests
  sid: "0a2c72e0-9e20-4c99-ac6c-91299623043d",
  name: "nordnet",
  iconUrl: "https://gateway-staging.finfollow.com/resources/nordnet.png",
},

Examples