Problem with getting token for authentication

1077
5
10-02-2012 08:04 PM
c_f_ong
New Contributor III
Hello

I'm trying to access a secured service that requires a token. When I input the getToken url into a browser, I could get the token JSON response without any problem. However, when I try to execute it within my code as follows:

    NSURL *url = [NSURL URLWithString:@"http://.../getToken"];
    NSString *json = @"{\"accessKEY\":\"i...\"}";
    NSDictionary *jsonDict = [json AGSJSONValue];
    AGSJSONRequestOperation *jsonOp = [[[AGSJSONRequestOperation alloc] initWithURL:url queryParameters:jsonDict] autorelease];

Output:
{"GetToken":[{"Invalid Access":"IP Address"}]}

Any idea as to what may be the cause of the above problem? Any workaround?

Thanks.

Rgds
Ong CF
0 Kudos
5 Replies
ChrisRiver
New Contributor III
Just out of curiosity, could you use the AGSCredential class instead of manually asking for the token?

AGSCredential *myCredential = [[AGSCredential alloc] initWithUser:[jsonDict objectForKey:@"username"] password:[jsonDict objectForKey:@"password"]  authenticationType:AGSAuthenticationTypeToken tokenUrl:url];


You can access the token provided here using:

myCredential.token;


I believe all the AGS classes that are used to access services that may or may not be secured have a "credential:" optional argument.  So in this case if you wanted to get information about a secured map service you'd do this:

NSError *serviceError = nil;
AGSMapServiceInfo *serviceInfo = [[AGSMapServiceInfo alloc] initWithURL:mapServiceEndpoint credential:myCredential error:&serviceError];


I know this wasn't exactly what you were asking, but hope it helps.

Chris
0 Kudos
NimeshJarecha
Esri Regular Contributor
Please go through secured services document and let me know if you have any specific question.

Regards,
Nimesh
0 Kudos
AshishArora
New Contributor III
Please go through secured services document and let me know if you have any specific question.

Regards,
Nimesh


Is it possible to validate the generated token externally (like valid or not valid)
0 Kudos
NimeshJarecha
Esri Regular Contributor
No, it is server's responsibility.

Regards,
Nimesh
0 Kudos
AshishArora
New Contributor III
No, it is server's responsibility.

Regards,
Nimesh


Thanks Nimesh
0 Kudos