eddof13

Bugs/Issues with Token service and iOS

Discussion created by eddof13 on Aug 2, 2011
Latest reply on Aug 3, 2011 by eddof13
Hi,

I am noticing some issues with the token service as well as iOS. I may do a cross post in an ArcServer forum as well.

First off, this isn't iOS specific, but I am having a problem with domain logins regarding the token service.

1) http://server/arcgis/manager requires my login in the form server\edward.jesinsky
2) http://server/arcgis/rest/admin accepts my login either way: server\edward.jesinsky or edward.jesinsky
3) http://server/arcgis/tokens/gettoken.html accepts my login either way as well, however: server\edward.jesinsky generates valid tokens, while just edward.jesinsky does not (they generate invalid token errors when connecting to secured services). It seems to me that if I am able to login without my domain and generate the token, then the token should work. If only there was some consistency between logins.

Now, that I mention those issues with the token service, this also affects me with the iOS api.

1) Using the following code:
NSURL *tokUrl = [NSURL URLWithString:@"http://server/ArcGIS/tokens"];
AGSCredential *cred =[[[AGSCredential alloc] initWithUser:@"edward.jesinsky" password:@"password" authenticationType:AGSAuthenticationTypeToken tokenUrl:tokUrl] autorelease];
 
NSURL *securedUrl = [NSURL URLWithString:@"http://server/ArcGIS/rest/services/hello/MapServer"];
AGSDynamicMapServiceLayer *securedLayer = [AGSDynamicMapServiceLayer dynamicMapServiceLayerWithURL:securedUrl credential:cred];
 
[self.mapView addMapLayer:securedLayer withName:@"Secured Layer"];


I get the resulting error:
2011-08-02 13:23:46.066 Untitled[12932:40b] Error: Error Domain=NSCocoaErrorDomain Code=499 "Unauthorized access" UserInfo=0x601ec70 {NSLocalizedFailureReason=, NSURL=http://server/ArcGIS/rest/services/hello/MapServer?f=json&token=beepbooptokenhere, NSLocalizedDescription=Unauthorized access}


This is unexpected because as mentioned, tokens without my domain login ie edward.jesinsky work with the requesting tokens and rest api, but I'm still getting Invalid token when trying to access a mapservice like:
http://server/arcgis/rest/services/hello/MapServer?f=json&token=tokenhere


Oh, of course, why don't I change my username above into something like server\edward.jesinsky? When I try that, I get the following:

2011-08-02 13:31:01.307 Untitled[13082:40b] Error: Error Domain=NSCocoaErrorDomain Code=401 "Invalid Credentials" UserInfo=0x64066a0 {NSLocalizedDescription=Invalid Credentials}


Which is surprising, because that login works fine through other means of retrieving tokens, such as server/arcgis/tokens/gettoken.html or through GET parameters:
http://server/arcgis/tokens?request=gettoken&username=server\edward.jesinsky&password=password&clientid=ip.1.2.3.4&expiration=1440


So far, my solution has been to manually generate a token and then hard code it like the following:
AGSCredential *cred = [[[AGSCredential alloc] initWithToken:@"supertoken"] autorelease];


There is one last issue I have run into with iOS tokens. Supposing I did not use a domain login to request a token, then the credential issue shouldn't be a problem when using the automatic token retrieval support. However, there is still the problem with referrers. AGSCredential appears to lack an obvious means of setting the referrer to use when requesting a token. Where is the initWithUser:referrer? The tokens that the service generate are coming up with the following token (when I decrypt it):
edward.jesinsky:1312309426990: :ref.arcgisios


Which doesn't surprise me that it does not work, as I don't think that is a valid referrer. If someone knows how I can create tokens such as this one through iOS I'd appreciate it.
server\edward.jesinsky:1312309426990: :ip.1.2.3.4


Thank you, I apologize for the long post. Hopefully I can get some answers!

Note: cross post: http://forums.arcgis.com/threads/36199-Bugs-Issues-with-Token-service-%28and-iOS%29

Outcomes