Is it possible to enter credentials in code?

1112
4
Jump to solution
09-21-2021 06:16 PM
ThomasKellough
New Contributor

I'm loading a map that has some specific layers through a server that is password protected. I'd like to be able to enter the username and password in code and NOT have this popup occur. I know you can cache it and it will log itself in when you leave the screen and go back, but is there a way to get the initial login to occur through code and even update as necessary as long as username and password do not change? I'm trying to prevent my users from doing too much work in order to use this. 

Screen Shot 2021-09-21 at 7.13.48 PM.png

0 Kudos
1 Solution

Accepted Solutions
Ting
by Esri Contributor
Esri Contributor

Hi Thomas,

It should be possible using AGSCredential. We may need specific context to better help you, but here are some general examples

- Use AGSAuthenticationManagerDelegate to catch the authentication challenge and pass in your credentials: https://github.com/Esri/arcgis-runtime-samples-ios/blob/main/arcgis-ios-sdk-samples/Layers/Display%2... . Don't forget to set AGSAuthenticationManager.shared().delegate

- If you are using an AGSServiceGeodatabase, you can directly set the credentials on it: https://github.com/Esri/arcgis-runtime-samples-ios/blob/main/arcgis-ios-sdk-samples/Edit%20data/Edit... 

Though it is not recommended to hardcode your credentials in code due to security concerns. Proceed with caution if you understand the usecase clearly.

Hope it helps! 🙂

View solution in original post

0 Kudos
4 Replies
Ting
by Esri Contributor
Esri Contributor

Hi Thomas,

It should be possible using AGSCredential. We may need specific context to better help you, but here are some general examples

- Use AGSAuthenticationManagerDelegate to catch the authentication challenge and pass in your credentials: https://github.com/Esri/arcgis-runtime-samples-ios/blob/main/arcgis-ios-sdk-samples/Layers/Display%2... . Don't forget to set AGSAuthenticationManager.shared().delegate

- If you are using an AGSServiceGeodatabase, you can directly set the credentials on it: https://github.com/Esri/arcgis-runtime-samples-ios/blob/main/arcgis-ios-sdk-samples/Edit%20data/Edit... 

Though it is not recommended to hardcode your credentials in code due to security concerns. Proceed with caution if you understand the usecase clearly.

Hope it helps! 🙂

0 Kudos
ThomasKellough
New Contributor

Hi Ting,

 

Thanks so much for that. AGSAuthenticationManagerDelegate was exactly what I needed!

And thanks for the tip on the hard coding - I probably should have been more specific. I'll be collecting the username/password through another request and using that - so no hardcoding 🙂

Thanks so much again for your quick and correct response.

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Note also that you can lean on the keychain to reduce the frequency with which users will be asked to log in. You can look at AGSAuthenticationManager.shared.credentialCache and call enableAutoSyncToKeychain(). This will securely cache credentials in the keychain, ready for your user to use next time they open the app.

0 Kudos
ThomasKellough
New Contributor

Thank you for that tip! That will definitely help out. 

0 Kudos