Select to view content in your preferred language

Authenticating directly on a service

659
2
Jump to solution
07-28-2023 05:11 AM
frankm
by
Occasional Contributor

So, I am doing some digging into an older app using the runtime sdk, and was trying to reproduce some functionality using the Maps SDK.

In the old app, they are creating a service feature table, authenticating and then performing a query, something like this:

someService = AGSServiceFeatureTable(<with an url>)

// then setting credentials (to be used only with the service)

someService?.credential = AGSCredential(
    user: environment.portal.username,
    password: environment.portal.password
)

// some more code, setting featureRequestMode, etc
// then perform a queryFeatures on the service

 

However, in the new SDK, I think the equivalent service is the ServiceFeatureTable? But, I cannot set the credentials the same way. I am of course getting an error message indicating missing credentials.

My question is, is it possible, and if, how would I do this?

The problem is that I am to actually authenticate to a different service for other functionality, and this is a secondary "helper" service, and not really connectable with the other one, so it would be great to be able to fire up a authenticated connection on-the-fly.

1 Solution

Accepted Solutions
NimeshJarecha
Esri Regular Contributor

Hi Frank,

Like 100.x SDK, the credential property is not available in 200.x SDK. Please refer the Migrate authentication from 100.x to 200.x  doc for all the differences. 

You can create the credential and add it to the store before creating and loading the service feature table.

        let tokenCredential = try await TokenCredential.credential(
            for: URL(string: "<service feature table url>")!,
            username: "username",
            password: "password"
        )
        ArcGISEnvironment.authenticationManager.arcGISCredentialStore.add(tokenCredential)

        let table = ServiceFeatureTable(url: URL(string: "<service feature table url>")!)
        try await table.load()

 

Hope this helps!

 

Regards,

Nimesh

View solution in original post

2 Replies
NimeshJarecha
Esri Regular Contributor

Hi Frank,

Like 100.x SDK, the credential property is not available in 200.x SDK. Please refer the Migrate authentication from 100.x to 200.x  doc for all the differences. 

You can create the credential and add it to the store before creating and loading the service feature table.

        let tokenCredential = try await TokenCredential.credential(
            for: URL(string: "<service feature table url>")!,
            username: "username",
            password: "password"
        )
        ArcGISEnvironment.authenticationManager.arcGISCredentialStore.add(tokenCredential)

        let table = ServiceFeatureTable(url: URL(string: "<service feature table url>")!)
        try await table.load()

 

Hope this helps!

 

Regards,

Nimesh

frankm
by
Occasional Contributor

Perfect, this was just what I needed! Absolutely brilliant 🙂

0 Kudos