How To Authenticate to access content in ArcGIS Online

617
2
03-09-2018 12:15 PM
EricDUCOS1
New Contributor III

Hi,

I have a very simple thing to do, but I did not find any easy information to do it.

I have today a Xamarin app that use RuntimeSDK .NET. In this app, I have a MapView control that I initialize with a url that points to a WebMap that I created on my ArcGIS Online portal. The url is something like:

https://<myname>.maps.arcgis.com/home/webmap/viewer.html?webmap=<identifier>

As far as I share to everyone the WebMap and Featured layers that are included in my WebMap, there is no problem...

Now, I want to secure the access and allow only me as a user for accessing this resource.

I found that I can use this piece of code to give authentication but what to give as ServiceUrl to allow the application to acces my content ? I tried many url, but none worked...

var cred = await AuthenticationManager.Current.GenerateCredentialAsync(new Uri("<ServiceUrl>"), "<login>", "<password>");
AuthenticationManager.Current.AddCredential(cred);

Please help !!! I am a little lost with all (too many) possibilities that are described in the help, but without really samples that correspond to my needs.

Eric.

0 Kudos
2 Replies
TonyWakim
Esri Contributor

Eric, try something like this:

```

AuthenticationManager.Current.ChallengeHandler = new ChallengeHandler(async (info) =>

{

return await AuthenticationManager.Current.GenerateCredentialAsync(portalUri, UserName, Password);

});

 

var portal = await ArcGISPortal.CreateAsync(portalUri, true, CancellationToken.None);

```

for portalUri use: new Uri("https://<myname>.maps.arcgis.com")

0 Kudos
EricDUCOS1
New Contributor III

Hi Tony,

Thanks, it seems to work now...first, I only took the GenerateCredentialAsync without the ChallengeHandler that produced an exception...but when the line is called in the contexte of the ChallengeHandler, it works...

Regards.

Eric

0 Kudos