how to authenticate with token only to get a route with routeTask.createFromToken("x")?

364
1
05-16-2023 06:01 AM
JhostinLunaLunaHuanca
New Contributor

I'm trying to get a route with Arcgis routeTask adding the token obtained from the service but it doesn't work correctly, sometimes it succeeds in authenticating and other times it doesn't, could you please help me?

I am using the java sdk..

var credential: UserCredential = UserCredential.createFromToken(arcgisToken,"www.arcgis.com")
  
fun solveRoute(){
   val rouTask = RouteTask(appContext,"https://route- 
   api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World")
   rouTask.credential = credential          
   AuthenticationManager.setAuthenticationChallengeHandler(this)
   rouTask.loadAsync()
   rouTask.addDoneLoadingListener {
   //
   }
}
override fun handleChallenge(p0: AuthenticationChallenge?): AuthenticationChallengeResponse {
        return AuthenticationChallengeResponse(
            AuthenticationChallengeResponse.Action.CONTINUE_WITH_CREDENTIAL,
            credential
        )
    }

 

Tags (2)
0 Kudos
1 Reply
Rachael_Ellen
Esri Contributor

Hello, 

It looks like you are working with the ArcGIS Runtime API for Android or ArcGIS Maps SDK for Kotlin here. I'll move your post to that forum (this particular forum is for the Java Maps SDK to build apps for Windows, Linux and macOS platforms).

In the meanwhile, you might find it helpful to have a look at the Find Route sample on the Android-Java samples webpage, or the same sample on the Kotlin sample code page. The sample shows how to set up a route task. For authentication challenges, have a look at the Cloud and Portal section on the Sample Code homepage.

0 Kudos