Skip to main content

Integrate Strong Customer Authentication in a mobile app

If you want to embed Swan into your own mobile app, you'll need to integrate Strong Customer Authentication (SCA) using in-app browsers.

By default, when a user performs SCA in a mobile app, Swan opens the smartphone's default browser and redirects the user out of the mobile app to complete SCA. Once SCA is complete, the user must exit their smartphone browser and return to the mobile app.

With SCA integration, you can embed an in-app browser directly into your mobile app so SCA opens within the application. Once SCA is complete, the user closes the in-app browser and remains inside your mobile app.

Open Swan pages in the top-level browser only

Don't open Swan's authorization, consent, or sensitive card information pages:

  • In an iframe
  • In a WebView
  • In a popup (for example, with window.open)

Swan no longer supports these flows, and they stop working from 31 December 2026.

Instead, redirect the user to the URL:

  • On the web, in the current browser tab.
  • In a mobile app, in the device's browser or an in-app browser tab (SFSafariViewController on iOS, Chrome Custom Tabs on Android).

Building a web app instead? Read Integrate Strong Customer Authentication in a web app.

When to use SCA integration​

SCA integration is relevant when you have a mobile app and your users perform all actions from the mobile app. This improves the user experience by keeping users inside your mobile app rather than redirecting them to an external browser.

Overview​

SCA integration works for both OAuth (login/authentication) and Consent (sensitive operations) flows.

To integrate Swan's Strong Customer Authentication (SCA), you'll need:

  1. An in-app browser package.
  2. A custom URL scheme with a deep link listener package.
  3. A backend server (this guide uses https://my-company-api.com).

Check out Swan's demo app GitHub repository for an integration example.

Step 1: Set up your in-app browser​

Use the documentation for your system's recommended API to set up your in-app browser.

SystemAPIReference
AndroidCustom Tabs APISwan implementation
iOSSFSafariViewController APISwan implementation

We provide an official React Native package: @swan-io/react-native-browser

Follow the references

When using frameworks other than React Native, ensure that your package is configured in a way that follows Swan's implementation references.

Use the documentation for your system's recommended tutorial to set up the deep link listener for your app.

SystemRecommended guide
AndroidCreate deep links to app content
iOSDefining a custom URL scheme for your app

If you are using React Native, follow this guide.

Step 3: Configure the sign-in process​

This five-step process describes an ideal path for your users to sign in.

3.1 Sign-in button​

First, the user clicks a sign-in button in your app. Clicking this button opens an in-app browser and starts listening for deep links.

Linking.addListener("url", ({ url }) => {
// called when deep link is visited
});

// …

openBrowser("https://my-company-api.com/auth").catch((error) => {
console.error(error);
});

3.2 Authorization URL​

Next, your server constructs a Swan authorization URL and redirects the user.

app.get("/auth", async (req, reply) => {
const params = querystring.encode({
client_id: "$YOUR_CLIENT_ID",
response_type: "code",
redirect_uri: "https://my-company-api.com/auth/callback", // must be registered in our dashboard
scope: ["openid", "offline"].join(" "),
state: generateUserState(req),
});

return reply.redirect(`https://oauth.swan.io/oauth2/auth?${params}`);
});

3.3 User logs in​

The user logs in and is redirected to https://my-company-api.com/auth/callback.

3.4 Server responds​

Your server:

  1. Reads the authorization code.
  2. Exchanges it for a user access token.
  3. Stores the token using a unique identifier.
  4. Redirects the user to a deep link.
app.get("/auth/callback", async (req, reply) => {
if (req.query.state !== generateUserState(req)) {
throw new Error("Something isn't right, abort");
}

const token = await client.post("https://oauth.swan.io/oauth2/token", {
client_id: "$YOUR_CLIENT_ID",
client_secret: "$YOUR_CLIENT_SECRET",
grant_type: "authorization_code",
code: req.query.code,
redirect_uri: "https://my-company-api.com/auth/callback",
});

const sessionId = randomUUID();
await storeTokenInKeyValueStore(sessionId, token);

return reply.redirect(`com.company.myapp://close?sessionId=${sessionId}`);
});

3.5 Close browser and store identifier​

Finally, the listener closes the in-app browser and stores the identifier.

Linking.addListener("url", ({ url }) => {
// called when deep link is visited

if (url.startsWith("com.company.myapp://close")) {
closeBrowser(); // required on iOS

const { query } = parseUrl(url);

if (query.sessionId) {
AsyncStorage.setItem("sessionId", query.sessionId);
}
}
});

// …

openBrowser("https://my-company-api.com/auth").catch((error) => {
console.error(error);
});

This six-step process describes an ideal path for your users to consent. This example uses the action of creating a card.

First, the user clicks a Create a card button in your app. Your server API receives the call with the following sessionId header.

const sessionId = await AsyncStorage.getItem("sessionId");

await client.post("https://my-company-api.com/add-card", {
headers: { sessionId },
});

Your server calls the Swan API with a user access token and returns the consentUrl.

app.get("/add-card", async (req, reply) => {
const token = await getTokenFromKeyValueStore(req.headers.sessionId);

const { consentUrl } = await swanClient.addCard(
{
input: {
// …
consentRedirectUrl: "https://my-company-api.com/add-card/callback",
},
},
{
headers: {
Authorization: `Bearer $TOKEN`,
},
}
);

return reply.json({ consentUrl });
});

The app opens an in-app browser and starts listening for deep links.

Linking.addListener("url", ({ url }) => {
// called when deep link is visited
});

// …

const sessionId = await AsyncStorage.getItem("sessionId");

const { consentUrl } = await client.post(
"https://my-company-api.com/add-card",
{ headers: { sessionId } }
);

openBrowser(consentUrl).catch((error) => {
console.error(error);
});

The user consents and is redirected to https://my-company-api.com/add-card/callback.

During redirection, Swan adds these query parameters to the URL.

  • consentId.
  • env: Sandbox or Live.
  • status: Accepted, CustomerRefused, OperationCommitting, Created, Started, Expired, Failed, or Canceled.
    • Including the status doesn't replace the need to query Swan's API to confirm the consent.
  • resourceId (if the consent only impacts one resource).

Your server performs any necessary additional operations, then redirects the user to a deep link.

app.get("/add-card/callback", async (req, reply) => {
// perform additional operations…
return reply.redirect("com.company.myapp://close");
});

Finally, the listener closes the in-app browser.

Linking.addListener("url", ({ url }) => {
// called when deep link is visited

if (url.startsWith("com.company.myapp://close")) {
closeBrowser(); // required on iOS
}
});

const sessionId = await AsyncStorage.getItem("sessionId");

const { consentUrl } = await client.post(
"https://my-company-api.com/add-card",
{ headers: { sessionId } }
);

openBrowser(consentUrl).catch((error) => {
console.error(error);
});

Security recommendations​

The examples on this page are deliberately minimal. In production, treat the deep link as a public channel: any app on the device can register your custom URL scheme, and anyone can send your user a crafted link.

Do

  • Redirect to your app with a short-lived, single-use code, and have the app exchange it for its session over HTTPS.
  • Bind that code to the app that started sign-in with a PKCE verifier, so an intercepted code is useless.
  • Only handle a callback while a sign-in started by your app is in progress.
  • Store the session identifier in the device's secure storage (Keychain on iOS, Keystore on Android).
  • Keep Swan tokens on your server, refresh them there, and revoke them when the user logs out.
  • Confirm the consent status by querying Swan's API from your server.

Don't

  • Don't put a session identifier or a token in the deep link.
  • Don't store the session identifier in AsyncStorage or other unencrypted storage.
  • Don't trust the query parameters of a callback without checking them on your server.