Skip to content

ArcGISOAuthHybridInitialize

Using ArcGISOAuthHybridInitialize, you can display ArcGIS Online content by signing in with OAuth2.

ArcGISOAuthHybridInitialize Function

Attempts authentication with Application Credentials, and automatically falls back to user login if it fails. Waits until authentication is complete.

suspend fun ArcGISOAuthHybridInitialize(
authenticatorState: AuthenticatorState,
portalUrl: String,
redirectUrl: String,
clientId: String,
clientSecret: String? = null,
): Boolean

Parameters

  • authenticatorState: AuthenticatorState that manages authentication state
  • portalUrl: URL of the ArcGIS Portal
  • redirectUrl: OAuth Redirect URI
  • clientId: OAuth Client ID
  • clientSecret: OAuth Client Secret. If omitted, a login dialog will be displayed.

Usage Example of ArcGISOAuthHybridInitialize

Displaying private content managed in Portal by specifying ClientID and ClientSecret.

@Composable
fun BasicMapExample(modifier: Modifier = Modifier) {
// Map camera position
val mapViewState =
rememberArcGISMapViewState(
cameraPosition =
MapCameraPosition(
position = GeoPoint.fromLatLong(35.6812, 139.7671),
zoom = 12.0,
),
)
// Authentication state and CoroutineScope (for sequential processing like await)
val authenticatorState = remember { AuthenticatorState() }
val scope = rememberCoroutineScope()
ArcGISMapView(
state = mapViewState,
modifier = modifier.fillMaxSize(),
sdkInitialize = { context ->
ArcGISOAuthHybridInitialize(
authenticatorState = authenticatorState,
portalUrl = "(ArcGIS Portal URL)",
redirectUrl = "(Redirect URL)",
clientId = (APP CLIENT ID),
clientSecret = "(APP CLIENT SECRET)",
)
},
onMapLoaded = {
scope.launch {
val holder = mapViewState.getMapViewHolder() ?: return@launch
// Execute sequentially like await
val portal = Portal("https://mkgeeklab.maps.arcgis.com/", Portal.Connection.Authenticated)
portal.load().getOrThrow()
val item = PortalItem(portal, "e0ce06974e3d4c79b37e30d224c585d3")
item.load().getOrThrow()
when (item.type) {
is PortalItemType.WebScene -> {
ArcGISScene(item).also {
it.load().getOrThrow() // Wait for WebScene to finish loading
holder.map.scene = it
}
}
is PortalItemType.WebMap -> error("SceneView only supports WebScene")
else -> error("Unknown item type: ${item.type}")
}
// Additional layer example (optional)
val trafficServerUrl = "https://traffic.arcgis.com/arcgis/rest/services/World/Traffic/MapServer"
ArcGISMapImageLayer(trafficServerUrl).also {
it.opacity = 0.6f
holder.map.scene!!.operationalLayers.add(0, it)
}
}
}
) {}
// Authentication UI (for user login). Used as fallback for hybrid authentication.
Authenticator(authenticatorState = authenticatorState, modifier = modifier)
}