In my C# application, I am trying to access a Feature service which is hosted on arcgis.com. The feature service is shared only with a group or organization and is NOT public. How can I access this service in my client code. Here is my client code which throws an exception saying the Authentication Token required. I do have the token but dont know how to use that token to be authenticated to use the service. This same code runs fine for services that are shared as PUBLIC.

   IPropertySet sipPS = new PropertySet();
    sipPS.SetProperty("DATABASE", layerUrl);
    IWorkspaceFactory sipWSF = (IWorkspaceFactory)new ESRI.ArcGIS.Carto.FeatureServiceWorkspaceFactory();
    IWorkspace sipWS = sipWSF.Open(sipPS, 0);
    IFeatureWorkspace sipFWS = (IFeatureWorkspace)sipWS;
    IGroupLayer grpLayer = new GroupLayerClass();
    grpLayer.Name = Constants.ArcGISOnlineGroupLayerName;
    IFeatureClass sipFC = sipFWS.OpenFeatureClass("0");
    IFeatureLayer fl = new FeatureLayerClass();
    fl.Name = featureLayerName;
    fl.FeatureClass = sipFC;
    grpLayer.Add(fl as ILayer);
  • Are you wanting to setup user logins or app logins for your application? Also, does your application use OAuth 2-based APIs? Discussion Link: resources.arcgis.com/en/help/arcgis-rest-api/index.html#//…
    – Baltok
    Commented Oct 21, 2014 at 18:45
  • I am not using OAuth 2-based api for authentication. I am simply generating a token using GenerateToken query by passing in the user's login credentials. After logging in, I published a service on Arcgis.com and shared that with a group. Since the service is not shared as Public, when I myself, or group to which the service is shared, tries to consume this service, "Authentication token required" error appears. I do have the token but I dont know how can I use that token to successfully consume the secure service.
    – WAQ
    Commented Oct 22, 2014 at 3:40
  • This has been cross-posted as a direct copy from stackoverflow.com/questions/26429713/… but has had a bounty added on both sites
    – PolyGeo
    Commented Oct 22, 2014 at 22:54
  • @PolyGeo I posted copy of same question on two places because I need urgent reply. Is that violation of some rule or what?
    – WAQ
    Commented Oct 23, 2014 at 5:49
  • The policy on cross-posting to multiple SO/SE sites has been discussed at meta.stackexchange.com/questions/64068/… However, by placing a bounty on the same question at both sites, my understanding is that they cannot be closed on either site (meta.stackexchange.com/questions/14591/…). Nevertheless by making potential answerers from both sites aware of the Q&A on the other it may lead to synergies and a faster solution.
    – PolyGeo
    Commented Oct 23, 2014 at 6:23

3 Answers 3


Your layerUrl is similar at: http://services1.arcgis.com/cFi1BRRsYB2fYqCl/arcgis/rest/services/NameService/FeatureServer

Just add the token to Url: http://services1.arcgis.com/cFi1BRRsYB2fYqCl/arcgis/rest/services/NameService/FeatureServer?token=gGIYjUwXvaO75l1X7LHsgOo2Yueoh1jTGRvrKm7K9ZBE-0TY-EA_Ml7vJtllQK9P2nngX5ciedKgHkjLOEgRSKYR8QhDJMDpWQ09PhTWubNACuFsNIQ3fdlbS6tsPO0h

  • I did try to append the token with the layerUrl, but had no luck. I used Fiddler app to see what urls are being generated by the API or the network, but I dont see only http://services1.arcgis.com/cFi1BRRsYB2fYqCl/arcgis/rest/services/NameService/FeatureServer being sent over the network even after appending the token with the layerUrl.
    – WAQ
    Commented Oct 23, 2014 at 4:34
  • On AGOL, under my contents click on "Open in ArcGIS for Desktop" and start the download of the file item.pitem. In this file you can find the url of the feature layer. Add "?token=<yourtoken>&f=json" to the url and open it in a browser. Tell me what happening.
    – lele3p
    Commented Oct 23, 2014 at 11:16
  • I do have the Url of the layer which is "http://services2.arcgis.com/js0B5yfJ0ZQG/arcgis/rest/services/TxsUltural/FeatureServer and I also have the token generated. lets assume token is abc112asdfkljznxc123123lkjkj23klj so complete url is like "http://services2.arcgis.com/js0B5yfJ0ZQG/arcgis/rest/services/TxsUltural/FeatureServer?token=abc112asdfkljznxc123123lkdfkj23klj" And I have also tried with individual sublayers like url:"http://services2.arcgis.com/js0BC5yf1J0Z4Q5G/arcgis/rest/services/texas_cultural/FeatureServer/1?token=abc112asdfkljznxc123123lkjadfkj23klj" but no luck
    – WAQ
    Commented Oct 23, 2014 at 11:50
  • I am able to view the layer in browser using above url and token. Its just that I am getting Token Authentication required exception when I use it in code that is posted in original Question :)
    – WAQ
    Commented Oct 23, 2014 at 11:52
  • total stab in dark - might the PropertySet have an undocumented TOKEN property?
    – MC5
    Commented Oct 23, 2014 at 14:31

Please refer the below link, seems to be that you do have some proxy issue. For accessing a secured services you need to have username and password and just write a code where token is generated at run time and you just need to append it properly


  • I do have the user name, password and have generated the token using generateToken query. Just not able to retrieve the secure services that I have published.
    – WAQ
    Commented Oct 23, 2014 at 5:47

This example post from the GeoNet forum is javascript-based, but it essentially accomplishes what you want to happen.

However, for the case of ESRI's 'ArcObjects for .Net' API (which we can tell you are using based on the Namespaces) you should implement the IArcGISSingleSignon.GetToken method. This object's method will sign on a user to ArcGIS Online (AGOL) and return a token. The workspace factory and the featureclass object definitions do not require the token, but the signon must occur before accessing secured AGOL feature services.

Lastly, just as an API point, IWorkspaceFactory is obsolete and IWorkspaceFactory2 is now the preferred interface object.--the signatures didn't change but the backend implementations did.

Please post to confirm your C# add-in correctly connects to AGOL once you implement single-signon tokens using the GetToken method.

  • I did try `IArcGISSingleSignOn.GetToken' and got the token generated after inputting my credentials to the sign in dialog that appears. Afterwards executed the same code as in the question, but still getting the same exception "Authentication token required".
    – WAQ
    Commented Oct 23, 2014 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.