Unico IDCloud - DevCenter
HomepageAuthenticationAPIsSDKs
English (United States)
English (United States)
  • Welcome
  • GETTING STARTED
    • Unico IDCloud
    • Capabilities
    • Integration Methods
    • Capabilities and Integration Methods
  • INTEGRATIONS
    • Quickstart
    • Authentication
      • Creating a Service Account
      • Preparing to Make an Authenticated API Request
      • Additional Resources
        • Example in Javascript
        • Authentication Errors
        • Postman Collection
    • Integration by Unico
      • Overview
      • API
        • API Reference
          • CreateProcess
            • CreateProcess separated by flows
          • GetProcess
          • GetSelfie
          • GetEvidenceSet
            • Specification of the evidential set
          • GetDocumentSigned
          • GetEvidenceSign
        • Errors
      • Controlling the experience
        • Redirecting the user
        • SDK
        • QR Code
        • Customizations
      • Additional Resources
        • Postman Collection
        • PoCs available
    • Integration by Client
      • Overview
      • API
        • API Reference
          • Liveness + Identity Verification + Behavior Alert
          • Liveness + Identity Verification + Behavior Alert + Risk Score
          • Liveness + Validation (1:1) + Behavior Alert
          • Document Capture and Reuse
        • Response Scenarios
        • Additional Resources
          • Postman Collection
      • Capture standard (without SDK)
    • Webhook
    • SDK
      • Overview
      • Update Policy
      • SDK Integration
        • Android SDK
          • Installation Guide
          • Usage and Integration Guide
            • Selfie Capture
            • Document Capture
          • Error Handling Guide
          • Android Customization
          • Troubleshooting
          • Release notes
        • iOS SDK
          • Installation Guide
          • Usage and Integration Guide
            • Selfie Capture
            • Document Capture
          • Error Handling Guide
          • iOS Customization
          • Troubleshooting
          • Release notes
        • Flutter SDK
          • Installation Guide
          • Usage and Integration Guide
            • Selfie Capture
            • Document Capture
          • Error Handling Guide
          • Flutter Customization
          • Troubleshooting
          • Release notes
        • Web SDK
          • Installation Guide
          • Usage and Integration Guide
            • Selfie Capture
            • Document Capture
            • Accessibility
          • Error Handling Guide
          • Web Customization
          • Release notes
      • Additional Resources
        • Available PoCs
        • Best Practices for SDK Implementation
  • help & faq
    • Glossary
    • Help Center
Powered by GitBook

Institucional

  • Sobre nós

Copyright © 2024 unico. All rights reserved

On this page

Was this helpful?

Export as PDF
  1. INTEGRATIONS
  2. Integration by Unico
  3. Controlling the experience

Redirecting the user

In this section, you will find information on how to redirect a user in your applications within the by Unico experience

PreviousControlling the experienceNextSDK

Last updated 5 months ago

Was this helpful?


he userRedirectUrl field is used to direct the user. This field is received in the success response of the process creation when making the CreateProcess request.

Here you will find three ways to manage the user experience in web applications:

(1) Using Redirect:

It is recommended to follow these steps:

  • In your common flow (which includes the by Unico Registration), you will redirect the client to the link generated through the API;

  • After that, the client within the platform carries out the necessary procedures to continue the flow;

  • When completed, they are redirected to your page (using the redirectUrl provided during the process creation).

(2) Using window.open():

The window.open() option consists of opening a new tab in the user's browser so that they can complete the process. At the end, this tab is closed and redirected to your application.

For this, it is recommended to:

  • Follow the public documentation on this, which can be found ;

  • Monitorar se houve alteração de URL (para a redirectUrl) e então fechar a aba utilizando window.close().

Step 1: Using CustomTabs for Integration

1 - Add the necessary dependency for using CustomTabs in your app/build.gradle:

implementation("androidx.browser:browser:1.5.0")

Step 2: Opening a CustomTab

import android.net.Uri
import androidx.activity.ComponentActivity
import androidx.browser.customtabs.CustomTabsClient
import androidx.browser.customtabs.CustomTabsIntent

class CustomTabActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
       super.onCreate(savedInstanceState)

       openCustomTab(<URL_CBU>)
    }

    fun openCustomTab(url: String) {
        val builder = CustomTabsIntent.Builder()
        val customTabsIntent = builder.build()
        customTabsIntent.launchUrl(this, Uri.parse(url))
    }
}

Step 3: Modifying AndroidManifest

Add the necessary permissions and intents in the AndroidManifest.xml for the Activity that you want to receive the callback_uri. It is necessary to include the attribute android:launchMode="singleTop" as well as the <data> tag providing the URI data.

xml
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-permission android:name="android.permission.CAMERA"/> 
// ermissions for camera and geolocation are required

<activity
    android:name=".CustomTabActivity"
    android:exported="true"
    android:label="@string/app_name"
    android:theme="@style/Theme.Customtabs"
    android:launchMode="singleTop">

    <intent-filter android:label="Custom Tab">
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <!-- scheme e host são os dados fornecidos na criação de um processo no campo callback_uri
        callback_uri: "foobar://success?code=1234" -->
        <data android:scheme="foobar" android:host="success"/>
    </intent-filter>

</activity>

The following permissions are necessary for it to function correctly:

  • Camera

  • Geolocation

Step 4: Getting Return Information

o retrieve redirect information with the provided data, you can use the following code in the onNewIntent method of your Activity:

override fun onNewIntent(intent: Intent) {
    super.onNewIntent(intent)

    val url = intent.data
    val scheme = url.scheme // "foobar"
    val host = url.host // "success"
    val code = url.getQueryParameter("code") // "1234"
}

Passo 1: Criar o controlador de autenticação

1 - O primeiro passo é criar o controlador de autenticação, e, para isso crie uma classe chamada UnicoAuthenticationController (ou como preferir chamar).

2 - Na sequência, importe o framework AuthenticationServices no topo da classe.

3 - Declare a classe como NSObject e implemente o protocolo ASWebAuthenticationPresentationContextProviding.

  • O resultado deve ser:

import AuthenticationServices

class UnicoAuthenticationController: NSObject, ASWebAuthenticationPresentationContextProviding {
    func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
           if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
               if let mainWindow = windowScene.windows.first {
                   return mainWindow
               }
           }
           return ASPresentationAnchor()
       }
}

Passo 2: Implementar a autenticação

1 - Abra o arquivo onde você executa a autenticação e adicione as importações necessárias (como exemplo, o ContentView.swift é usado).

import SwiftUI
import AuthenticationServices

2 - Para controlar o estado do fluxo é preciso criar a propriedade @State.

@State private var finished = false

3 - Crie uma instância da classe UnicoAuthenticationController fora do corpo da estrutura ContentView.

let unicoController = UnicoAuthenticationController()

4 - Para a validação do processo, crie uma função chamada redirectUser.

func redirectUser() {
        guard let url = URL(string: "URL_AUTHENTICATION") else { return }

        var session: ASWebAuthenticationSession?
        session = ASWebAuthenticationSession(url: url, callbackURLScheme: "BUNDLE") { callbackURL, error in
            guard callbackURL != nil else {
                if let error = error {
                    return print("Erro durante o processo: \(error.localizedDescription)")
                }
                return
            }

            // Processa o URL de callback para verificar se o processo foi finalizado
            session?.cancel()
            finished = true
        }

        session?.presentationContextProvider = unicoController
        session?.prefersEphemeralWebBrowserSession = true
        session?.start()
    }

Ambientes:

Lembre-se de alterar a url URL_AUTHENTICATION para a URL de autenticação recebida em seu processo e também o callbackURLScheme BUNDLE para o redirect informado na criação do processo (o uso do Bundle Identifier de seu aplicativo é recomendado).

Autenticação única:

É importante setar prefersEphemeralWebBrowserSession para true para garantir uma autenticação única por processo.

It is also possible to use the link generated by Unico in hybrid frameworks. To do this, you can create a bridge between the framework used and the native one and follow as we suggest in the documents or use a library that makes these integration options available.

Integrating WebView into your application is the customer's sole responsibility, as this functionality is not offered as part of Unico's libraries or SDKs. Because of this, we do not offer technical support for questions or problems related to implementing WebView in your application. For configuration guidance, we recommend consulting the official documentation for the technology used in your project (e.g. React Native, Flutter, etc.).


Still need help?

Didn't find something or still need help? If you're already a client or partner, you can reach out through our .

here
​
Help Center