Select to view content in your preferred language

java httprequest arcgis server rest api longterm token

3013
5
02-23-2016 09:18 AM
ChristopheSCILLIERI
New Contributor II

Hi all,

We have a client javascript app that based on a java n-tier.

For layers security pupose, java part calls arcgis server via REST API to get an ident. token this way :

 

url = new URL( strUrl );

HttpURLConnection conn;

conn = (HttpURLConnection)url.openConnection();

conn.setRequestMethod( "POST" );

conn.setRequestProperty( "Accept-Charset", "UTF-8" );

conn.setRequestProperty( "Content-type", "application/x-www-form-urlencoded" );

conn.setRequestProperty( "Accept", "application/json" );

conn.setDoOutput( true );

conn.setDoInput( true );

 

BufferedWriter bw = new BufferedWriter( new OutputStreamWriter( ( conn.getOutputStream() ), "UTF-8" ) );

 

String params = "username" + "=" + URLEncoder.encode( user, "UTF-8" ); params += "&";

params += "password" + "=" + URLEncoder.encode( pW, "UTF-8" ); params += "&";

params += "client" + "=" + URLEncoder.encode( "referer", "UTF-8" ); params += "&";

params += "referer" + "=" + URLEncoder.encode( referer, "UTF-8" ); params += "&";

params += "expiration" + "=" + URLEncoder.encode( duration, "UTF-8" ); params += "&";

params += "f" + "=" + URLEncoder.encode( "json", "UTF-8" );

bw.write( params ); bw.flush(); bw.close();

 

if( conn.getResponseCode() == HttpURLConnection.HTTP_OK )

//here we go with the returned TOKEN

 

We pass the returned token to the javascript client app which is init with a "esri.id.initialize(..)" and it works fine.

But it seems that in this way we only generate short-lived tokens.

How to generate long-live tokens with the arcgis server API REST ?

 

regards.

Chris.

Tags (1)
5 Replies
JordanBaumgardner
Occasional Contributor III

I'm assuming duration is > 1 or two days.

Might be worth putting in a break point there and make sure you have the correct units.

0 Kudos
ChristopheSCILLIERI
New Contributor II

Well, this code works fine. I set parameters : "username", "password", "client", "referer", and "expiration" in minutes. I send the request to our arcgis server. And our server is returning a good usable short-term token, and a correct expiration date.

But the point is that I don't see anywhere to tell the server that I want a long-term token ?

Regards.

0 Kudos
JordanBaumgardner
Occasional Contributor III

So if you set Minutes = 600 (10 days) it doesn't work?

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

would 10 days be 14400 minutes?

10d x 24h x 60m = 14400

0 Kudos
ChristopheSCILLIERI
New Contributor II

Right, I can change on server.

I've even tried 200 days :

For this I had to configure the server on 288.000 minutes on the short-live token,

implying to set 200 days too on the long-term part.

BUT, the client is supposed to fit the server configuration and not the opposit !

Which means that if we have a customer using an arcgis server configured with ONLY long live token (e.g. long live token set to 5 days, short-live token set to 0), the REST API seems not to be able to get any valid token.

It seems that in the ARCGis Server REST API there is no way to choose between long/short token types.

0 Kudos