Select to view content in your preferred language

generating tokens for testing

2653
0
03-23-2015 05:14 PM
JohnGravois
Deactivated User
1 0 2,653

i do a lot more tinkering than writing production code, but i uncovered a gem recently that i thought would be helpful for anyone who gets tasked with R&D from time to time.

When you're interacting with Esri services that require authentication, you have lots of options.

  You can use OAuth to ask end users to sign in

  You can set up a proxy to store credentials safely (so that no one has to)

  You can leverage an IdentityManager

But what about when you just want to see what a service can do?

Back in the day we had to walk to school in the snow, uphill, both ways.

we started by calling to GenerateToken​ by hand, then we crafted another request and appended the GUIDy looking strings that came back.  Unfortunately, these tokens weren't valid directly in the browser, so we reissued the requests using Fiddler (after making sure to spoof the 'referer').  The good news is, those days are long gone!  Now getting a fresh token that can be tacked onto a browser request is a cinch.

Just login to http://developers.arcgis.com using your Organizational credentials (or free developer account) and click on the 'Applications' icon in the top righthand corner.

Screenshot 2015-03-23 16.54.10.png

If you've already created arcgis.com items for your applications, they'll appear.  If you haven't, creating a new registered placeholder app takes less than a minute.

Screenshot 2015-03-23 16.42.25.png

Afterward, not only can you retrieve a 'ClientId' and 'ClientSecret' for authenticating on behalf of your end users to consume services that burn credits in the app you're yet to write, but there's also a static token with an incredibly handy copy to clipboard link which can be used temporarily for testing while you're still figuring out exactly what you'd like to do.

Screenshot 2015-03-23 16.43.25.png

Create your own, add it to a request like this, and paste into the browser to see how easy it is to start routing

http://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/solve?token=<paste-you...

congratulations, you just spent 1/25th of a credit.

You know what to do next, go play around with Geoenrichment, (and Elevation, and Routing, and Batch Geocoding and Analysis and on and on)

Did i mention that we've also pushed a bunch of great improvements to the documentation on authentication too?   Check em out!

https://developers.arcgis.com/authentication/

Tags (4)
About the Author
ArcGIS Hub, anything open, JavaScript and baking bread.