> For the complete documentation index, see [llms.txt](https://docs.payments.thalescloud.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.payments.thalescloud.io/click-to-pay/es/integrate-the-d1-sdk/getting-started/configuration/5.-authentication/sdk-login/iniciar-sesion-en-multiples-usuarios-finales-y-emisores.md).

# Iniciar sesión en múltiples usuarios finales y emisores

The updated login API supports multiple `D1Task` instances and multiple issuer access tokens.

This is useful when one issuer application manages several issuers or several consumer IDs.

Key behaviors:

* Log in once with all relevant issuer access tokens.
* Use any configured `D1Task` instance after login without authenticating again.

{% tabs %}
{% tab title="Android" icon="google-play" %}
{% code lineNumbers="true" %}

```java
class D1Task {
  public void login(
            @NonNull final List<byte[]> issuerTokens,
            @NonNull final Callback<Void> callback
    );
}
```

{% endcode %}
{% endtab %}

{% tab title="iOS" icon="apple" %}
{% code overflow="wrap" lineNumbers="true" %}

```swift
class D1Task {
    public func login(_ issuerTokens: inout [Data]) async throws
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

#### Configure multiple `D1Task` instances

Create one `D1Task` instance per issuer and consumer combination.

{% tabs %}
{% tab title="Android Kotlin" icon="google-play" %}
{% code lineNumbers="true" %}

```kotlin
fun makeConfigCallback() = object : D1Task.ConfigCallback<Void?> {
    override fun onSuccess(data: Void?) {
        // configured successfully for $tag
    }
    override fun onError(exceptions: List<D1Exception>) {
        for (ex in exceptions) {
            // Handle errors as per "D1 SDK Integration – Error Management"
            // e.g., log/route by ex.code, ex.message
        }
    }
}

// Set up D1Task1 with ISSUER_ID_1 and CONSUMER_ID_1
val d1Task1 = D1Task.Builder()
    .setIssuerID("ISSUER_ID_1")
    // set up other variables, e.g. activity, URL
    .build()

// Configure with CONSUMER_ID_1
d1Task1.configure(
    makeConfigCallback(),
    ConfigParams.buildConfigCore("CONSUMER_ID_1")
)

// Set up D1Task2 with ISSUER_ID_1 and CONSUMER_ID_2
val d1Task2 = D1Task.Builder()
    .setIssuerID("ISSUER_ID_1")
    // set up other variables, e.g. activity, URL
    .build()

// Configure with CONSUMER_ID_2
d1Task2.configure(
    makeConfigCallback(),
    ConfigParams.buildConfigCore("CONSUMER_ID_2")
)

// Set up D1Task3 with ISSUER_ID_2 and CONSUMER_ID_3
val d1Task3 = D1Task.Builder()
    .setIssuerID("ISSUER_ID_2")
    // set up other variables, e.g. activity, URL
    .build()

// Configure with CONSUMER_ID_3
d1Task3.configure(
    makeConfigCallback(),
    ConfigParams.buildConfigCore("CONSUMER_ID_3")
)
```

{% endcode %}
{% endtab %}

{% tab title="iOS" icon="apple" %}
{% code overflow="wrap" lineNumbers="true" %}

```swift
// Set up D1Task1 with ISSUER_ID_1 and CONSUMER_ID_1
var comp1 = D1Task.Components()
comp1.issuerID = "ISSUER_ID_1"
// set up other variables, e.g. URL
let d1Task1 = comp1.task()

// Configure with CONSUMER_ID_1
let consumerID1 = "CONSUMER_ID_1"
let coreConfig1 = ConfigParams.coreConfig(consumerID: consumerID1)

do {
    try await d1Task1.configure([coreConfig1])
    // Configuration successful
} catch {
    // Handle errors as per D1 SDK Integration – Error Management documentation
}

// Set up D1Task2 with ISSUER_ID_1 and CONSUMER_ID_2
var comp2 = D1Task.Components()
comp2.issuerID = "ISSUER_ID_1"
// set up other variables, e.g. URL
let d1Task2 = comp2.task()

// Configure with CONSUMER_ID_2
let consumerID2 = "CONSUMER_ID_2"
let coreConfig2 = ConfigParams.coreConfig(consumerID: consumerID2)

do {
    try await d1Task2.configure([coreConfig2])
    // Configuration successful
} catch {
    // Handle errors as per D1 SDK Integration – Error Management documentation
}

// Set up D1Task3 with ISSUER_ID_2 and CONSUMER_ID_3
var comp3 = D1Task.Components()
comp3.issuerID = "ISSUER_ID_2"
// set up other variables, e.g. URL
let d1Task3 = comp3.task()

// Configure with CONSUMER_ID_3
let consumerID3 = "CONSUMER_ID_3"
let coreConfig3 = ConfigParams.coreConfig(consumerID: consumerID3)

do {
    try await d1Task3.configure([coreConfig3])
    // Configuration successful
} catch {
    // Handle errors as per D1 SDK Integration – Error Management documentation
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

#### Log in with multiple issuer access tokens

The `sub` claim of an issuer access token can contain multiple consumer IDs.

When present, separate the consumer IDs with spaces.

Example issuer access tokens:

{% code overflow="wrap" lineNumbers="true" %}

```java
{
  "jti": "M9JHKtLdfXu782EH3hMf_",
  "sub": "CONSUMER_ID_1 CONSUMER_ID_2",
  "iat": 1626836247,
  "exp": 1627441047,
  "scope": "digibank:mobilebanking digibank:ecommerce",
  "iss": "ISSUER_ID_1",
  "aud": "https://client-api.d1.thalescloud.io/oidc/ISSUER_ID_1"
}

{
  "jti": "M9JHKtLdfXu782EH3hMf_",
  "sub": "CONSUMER_ID_3",
  "iat": 1626836247,
  "exp": 1627441047,
  "scope": "digibank:mobilebanking digibank:ecommerce",
  "iss": "ISSUER_ID_2",
  "aud": "https://client-api.d1.thalescloud.io/oidc/ISSUER_ID_1"
}
```

{% endcode %}

The first issuer access token for `ISSUER_ID_1` includes `CONSUMER_ID_1` and `CONSUMER_ID_2`.

The second issuer access token for `ISSUER_ID_2` includes `CONSUMER_ID_3`.

You can call the login API from any previously created `D1Task` instance. After that, subsequent operations can continue without another login.

{% tabs %}
{% tab title="Android Kotlin" icon="google-play" %}
{% code lineNumbers="true" %}

```kotlin
val cbp = d1Task1.getBindingHash() // Must be called if client binding is enabled.

// TODO: replace with the issuer access token returned by your issuer backend. 
// The token must include cbp as a claim, if client binding is enabled.
val issuerToken1: ByteArray = byteArrayOf() 
val issuerToken2: ByteArray = byteArrayOf() 

// Build the list of tokens
val tokens = mutableListOf<ByteArray>()
tokens += issuerToken1
tokens += issuerToken2

// Single login using d1Task1 with all issuer access tokens
d1Task1.login(tokens, object : D1Task.Callback<Void?> {
    override fun onSuccess(data: Void?) {
        // Login successful — proceed with subsequent operations

        val cardId1 = "CARD_ID_1"
        val cardId2 = "CARD_ID_2"
        val cardId3 = "CARD_ID_3"

        d1Task1.getCardMetadata(cardId1, object : D1Task.Callback<CardMetadata> {
            override fun onSuccess(data: CardMetadata) {
                // Use metadata for task1
            }
            override fun onError(exception: D1Exception) {
                // Handle error for task1 metadata
            }
        })

        d1Task2.getCardMetadata(cardId2, object : D1Task.Callback<CardMetadata> {
            override fun onSuccess(data: CardMetadata) {
                // Use metadata for task2
            }
            override fun onError(exception: D1Exception) {
                // Handle error for task2 metadata
            }
        })

        d1Task3.getCardMetadata(cardId3, object : D1Task.Callback<CardMetadata> {
            override fun onSuccess(data: CardMetadata) {
                // Use metadata for task3
            }
            override fun onError(exception: D1Exception) {
                // Handle error for task3 metadata
            }
        })
    }

    override fun onError(exception: D1Exception) {
        // Handle login error
    }
})
```

{% endcode %}
{% endtab %}

{% tab title="iOS" icon="apple" %}
{% code overflow="wrap" lineNumbers="true" %}

```swift
let cardID1 = "CARD_ID_1"
let cardID2 = "CARD_ID_2"
let cardID3 = "CARD_ID_3"

// Login with any D1Task
do {
    let cbp = try await d1Task1.bindingHash() // Must be called if client binding is enabled.
    
    // TODO: replace with the issuer access token returned by your issuer backend.
    // The token must include cbp as a claim, if client binding is enabled.
    let issuerToken1 = Data() 
    let issuerToken2 = Data()
    var tokens = [issuerToken1, issuerToken2]

    // Use any configured D1Task instance for a single login call.
    try await d1Task1.login(&tokens)
    // Login successful
} catch {
    // Handle login error
}

// Using D1Task1 with cardMetadata API
do {
    let metadata = try await d1Task1.cardMetadata(cardID1)
    // Use metadata for CONSUMER_ID_1.
} catch {
    // Handle error
}

// Using D1Task2 with cardMetadata API
do {
    let metadata = try await d1Task2.cardMetadata(cardID2)
    // Use metadata for CONSUMER_ID_2.
} catch {
    // Handle error
}

// Using D1Task3 with cardMetadata API
do {
    let metadata = try await d1Task3.cardMetadata(cardID3)
    // Use metadata for CONSUMER_ID_3.
} catch {
    // Handle error
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Invalidate all issuer access tokens

To invalidate all tokens for all configured `D1Task` instances, use [SDK logout](broken://spaces/62lLFDcmLCeqqwmy4Fee/pages/UAcJzNrCmjg0IstElB9y).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.payments.thalescloud.io/click-to-pay/es/integrate-the-d1-sdk/getting-started/configuration/5.-authentication/sdk-login/iniciar-sesion-en-multiples-usuarios-finales-y-emisores.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
