Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion Documentation/implementation-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,26 @@ Brand Concierge expects the following keys to be present in the Configuration sh
- **`concierge.configId`**: String (datastream ID)
- **`concierge.region`**: String, optional (region identifier, e.g. `va6`, inserted into the Brand Concierge request path; omit to use the default unqualified endpoint)

ECID is read from Edge Identity shared state.
The full Edge Identity `identityMap` (including the ECID) is read from Edge Identity shared state and forwarded to Brand Concierge requests.

Another option for validation is to use Adobe Assurance. Refer to the [Mobile SDK validation guide](https://developer.adobe.com/client-sdks/home/getting-started/validate/).

---

## Identities

Brand Concierge forwards the full Edge Identity `identityMap` on every chat and feedback request. The ECID is always included automatically. To send additional identities (e.g. `hashedEmail`, `CRMID`, or a custom namespace), set them via the Edge Identity API — they are forwarded verbatim, so lowercasing/hashing is the app's responsibility:

```kotlin
val map = IdentityMap()
map.addItem(IdentityItem("<lowercased-sha256-email>", AuthenticatedState.AUTHENTICATED, false), "hashedEmail")
Identity.updateIdentities(map)
```

Namespace priority and identity-graph rules are configured server-side in Adobe Experience Platform; the SDK does not interpret or relabel namespaces.

---

## Authentication

If your backend requires proof of the user's identity, register a `ConciergeAuthTokenProvider` to supply an app-minted authentication token. Brand Concierge attaches it to every chat and feedback request until the provider is cleared.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ConciergeExtension(extensionApi: ExtensionApi) : Extension(extensionApi) {
SELF_TAG,
"Identity shared state event received."
)
ConciergeStateRepository.instance.updateExperienceCloudId(api, event)
ConciergeStateRepository.instance.updateIdentity(api, event)
} else if (event.isConsentSharedStateEvent()) {
Log.trace(
EXTENSION_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import kotlinx.coroutines.flow.update
/**
* Represents the state of the Concierge extension.
*
* @property experienceCloudId The Experience Cloud ID (ECID) from the EdgeIdentity extension.
* Null indicates the ECID is not yet available or failed to load.
* @property experienceCloudId The Experience Cloud ID (ECID) derived from [identityMap]. Used as
* the identity readiness signal. Null if not yet available.
* @property identityMap The full identityMap from the EdgeIdentity extension, carried verbatim so
* every namespace (not just ECID) is forwarded. Null if not yet available.
* @property configurationReady Indicates whether the configuration is ready.
* @property surfaces List of surface URLs set via the [ConciergeChat] surfaces parameter.
* @property conciergeServer Server URL from concierge.server configuration.
Expand All @@ -36,6 +38,7 @@ import kotlinx.coroutines.flow.update
*/
internal data class ConciergeState(
val experienceCloudId: String? = null,
val identityMap: Map<String, Any?>? = null,
val configurationReady: Boolean = false,
val surfaces: List<String> = emptyList(),
val conciergeServer: String? = null,
Expand Down Expand Up @@ -93,13 +96,13 @@ internal class ConciergeStateRepository internal constructor(
}

/**
* Updates the Experience Cloud ID.
* This should be called by the ConciergeExtension when ECID becomes available.
* Stores the full EdgeIdentity identityMap verbatim, along with the derived ECID.
* This should be called by the ConciergeExtension when identity becomes available.
*
* @param api The ExtensionApi instance
* @param event The event that triggered the update
*/
fun updateExperienceCloudId(api: ExtensionApi, event: Event) {
fun updateIdentity(api: ExtensionApi, event: Event) {
val edgeIdentitySharedState = getXDMSharedState(
api,
ConciergeConstants.SharedState.EdgeIdentity.EXTENSION_NAME,
Expand All @@ -112,29 +115,34 @@ internal class ConciergeStateRepository internal constructor(
edgeIdentitySharedState,
ConciergeConstants.SharedState.EdgeIdentity.IDENTITY_MAP,
null
)
val ecids: MutableList<MutableMap<String?, Any?>?> =
DataReader.optTypedListOfMap(
Any::class.java,
identityMap,
ConciergeConstants.SharedState.EdgeIdentity.ECID,
null
)
)?.takeIf { it.isNotEmpty() }

val ecidMap = ecids.firstOrNull()

val ecid =
DataReader.optString(ecidMap, ConciergeConstants.SharedState.EdgeIdentity.ID, null)
?.takeIf { it.isNotEmpty() }
_state.update { it.copy(experienceCloudId = ecid) }
_state.update {
it.copy(experienceCloudId = extractEcid(identityMap), identityMap = identityMap)
}
// Log namespace names only, never id values (PII).
Log.debug(
ConciergeConstants.EXTENSION_NAME,
LOG_TAG,
"Updated concierge state with ECID: $ecid"

"Updated concierge state with identityMap namespaces: ${identityMap?.keys}"
)
}

/**
* Extracts the ECID from the [identityMap], or null when absent or empty.
*/
private fun extractEcid(identityMap: Map<String, Any?>?): String? {
val ecidEntry = DataReader.optTypedListOfMap(
Any::class.java,
identityMap ?: return null,
ConciergeConstants.SharedState.EdgeIdentity.ECID,
null
)?.firstOrNull()

return DataReader.optString(ecidEntry, ConciergeConstants.SharedState.EdgeIdentity.ID, null)
?.takeIf { it.isNotEmpty() }
}

/**
* Updates the configuration ready state.
* This should be called by the ConciergeExtension when configuration becomes available.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.adobe.marketing.mobile.services.Log
import com.adobe.marketing.mobile.services.NetworkCallback
import com.adobe.marketing.mobile.services.NetworkRequest
import com.adobe.marketing.mobile.services.ServiceProvider
import org.json.JSONObject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
Expand Down Expand Up @@ -172,6 +173,18 @@ internal class ConciergeConversationServiceClient(
}
}

/**
* Serializes the identityMap verbatim for the request body's `xdm.identityMap`, so every
* namespace (not just ECID) is forwarded. [JSONObject] escapes keys and values, keeping
* customer-supplied ids injection-safe. Returns an empty object when the map is unavailable.
*/
private fun identityMapJson(state: ConciergeState): String {
// JSONObject.toString() returns null (rather than throwing) if the map can't be
// serialized; fall back to an empty object in that case.
val json: String? = JSONObject(state.identityMap.orEmpty()).toString()
return json ?: "{}"
}

/**
* Creates the JSON request body for the conversation request.
*/
Expand Down Expand Up @@ -200,13 +213,7 @@ internal class ConciergeConversationServiceClient(
}
},
"xdm": {
"identityMap": {
"ECID": [
{
"id": "${state.experienceCloudId?.escapedForJson() ?: "null"}"
}
]
}
"identityMap": ${identityMapJson(state)}
}
}
]
Expand Down Expand Up @@ -434,11 +441,7 @@ internal class ConciergeConversationServiceClient(
}
},
"xdm": {
"identityMap": {
"ECID": [{
"id": "${state.experienceCloudId?.escapedForJson() ?: "null"}"
}]
},
"identityMap": ${identityMapJson(state)},
"conversation": {
$xdmConversationFields
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ConciergeExtensionTest {
// ========== Event Processing Tests ==========

@Test
fun `processEvent calls updateExperienceCloudId for identity shared state event`() {
fun `processEvent calls updateIdentity for identity shared state event`() {
val event = Event.Builder(
"Identity Event",
EventType.HUB,
Expand All @@ -83,7 +83,7 @@ class ConciergeExtensionTest {

extension.processEvent(event)

verify(exactly = 1) { mockStateRepository.updateExperienceCloudId(mockApi, event) }
verify(exactly = 1) { mockStateRepository.updateIdentity(mockApi, event) }
}

@Test
Expand Down Expand Up @@ -492,7 +492,7 @@ class ConciergeExtensionTest {
extension.processEvent(identityEvent)
extension.processEvent(configEvent)

verify(exactly = 1) { mockStateRepository.updateExperienceCloudId(mockApi, identityEvent) }
verify(exactly = 1) { mockStateRepository.updateIdentity(mockApi, identityEvent) }
verify(exactly = 1) { mockStateRepository.updateConfiguration(mockConfigState) }
}

Expand All @@ -509,7 +509,7 @@ class ConciergeExtensionTest {
extension.processEvent(event)

// Then - no repository methods should be called
verify(exactly = 0) { mockStateRepository.updateExperienceCloudId(any(), any()) }
verify(exactly = 0) { mockStateRepository.updateIdentity(any(), any()) }
verify(exactly = 0) { mockStateRepository.updateConfiguration(any()) }
}

Expand All @@ -524,7 +524,7 @@ class ConciergeExtensionTest {
extension.processEvent(event)

// Then - no repository methods should be called
verify(exactly = 0) { mockStateRepository.updateExperienceCloudId(any(), any()) }
verify(exactly = 0) { mockStateRepository.updateIdentity(any(), any()) }
verify(exactly = 0) { mockStateRepository.updateConfiguration(any()) }
}

Expand Down Expand Up @@ -629,7 +629,7 @@ class ConciergeExtensionTest {
extension.processEvent(event1)
extension.processEvent(event2)

verify(exactly = 2) { mockStateRepository.updateExperienceCloudId(mockApi, any()) }
verify(exactly = 2) { mockStateRepository.updateIdentity(mockApi, any()) }
}

@Test
Expand Down Expand Up @@ -719,7 +719,7 @@ class ConciergeExtensionTest {

extension.processEvent(event)

verify(exactly = 0) { mockStateRepository.updateExperienceCloudId(any(), any()) }
verify(exactly = 0) { mockStateRepository.updateIdentity(any(), any()) }
verify(exactly = 0) { mockStateRepository.updateConfiguration(any()) }
}

Expand Down Expand Up @@ -767,7 +767,7 @@ class ConciergeExtensionTest {

extension.processEvent(event)

verify(exactly = 0) { mockStateRepository.updateExperienceCloudId(any(), any()) }
verify(exactly = 0) { mockStateRepository.updateIdentity(any(), any()) }
}

@Test
Expand Down Expand Up @@ -829,7 +829,7 @@ class ConciergeExtensionTest {
extension.processEvent(otherEvent)
extension.processEvent(identityEvent)

verify(exactly = 2) { mockStateRepository.updateExperienceCloudId(mockApi, identityEvent) }
verify(exactly = 2) { mockStateRepository.updateIdentity(mockApi, identityEvent) }
verify(exactly = 1) { mockStateRepository.updateConfiguration(mockConfigState) }
}
}
Expand Down
Loading
Loading