compaqdrew

HELP - [AGSFeatureLayer addFeatures] doesn't use token authentication

Discussion created by compaqdrew on Apr 17, 2011
Latest reply on Apr 19, 2011 by DGoyal-esristaff
I'm accessing a secured ArcGIS feature layer.  The feature layer definitely works, because I can access and display its features.  I create the feature layer like so:

NSURL *featureURL = [NSURL URLWithString:@"http://server/ArcGIS/rest/services/SeMAPS-GEO/FeatureServer/0"];
    AGSCredential *myCredential = [[[AGSCredential alloc] initWithUser:@"username" password:@"password" authenticationType:AGSAuthenticationTypeToken tokenUrl:[NSURL URLWithString:@"http://server/ArcGIS/tokens"]] autorelease];
    featureLayer= [AGSFeatureLayer featureServiceLayerWithURL:featureURL mode:AGSFeatureLayerModeOnDemand credential:myCredential];


And I can view the features on an AGSMapView, etc., and authentication is working.

The problem comes when it's time to add a new feature:
featureLayer.editingDelegate = self;
    AGSFeatureTemplate *template = [[featureLayer templates] objectAtIndex:0];
    AGSGraphic *feature = [featureLayer createFeatureWithTemplate:template];
    AGSMutablePolygon *poly = [[[AGSMutablePolygon alloc] initWithSpatialReference:[AGSSpatialReference spatialReferenceWithWKID:3857]] autorelease];
    [poly addRingToPolygon];
    [poly addPointToRing:[mapView toMapPoint:CGPointMake(0, 0)]];
    [poly addPointToRing:[mapView toMapPoint:CGPointMake(0,50)]];
    [poly addPointToRing:[mapView toMapPoint:CGPointMake(100, 100)]];
    feature.geometry = poly;
    [featureLayer addFeatures:[NSArray arrayWithObject:feature]];


This returns back an "Unauthorized access."

A little WireShark sniffing shows this as what's being sent to the server:
f=json&features=[{"geometry":{"spatialReference":{"wkid":3857},"rings":[[[-10550558,3831481.531450578],[-10550558,3831394.240051348],[-10550383.41720154,3831306.948652118]]]},"attributes":{"perimeter":null,"n_dpoints":null,"centerlong":null,"volume":null,"dateupdated":null,"size":null,"projectid":null,"meandepth":null,"datecreated":null,"maxdepth":null,"wateruse":null,"waterlevel":null,"centerlat":null,"name":null}}]


Notice what's missing?  No token!  Well obviously without a token it's going to be unauthorized access!

How do I get the addFeatures method to use a token for authentication?

Outcomes