<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Token validator in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/token-validator/m-p/334127#M30888</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The only time I get a 400 error is when I have a malformed URL. Are you sure you have the parameters in the URL correctly set (starting with a question mark, separated by an ampersand)? Also, if you are sending a POST request instead of a GET request, the parameters need to be passed as data, not in the URL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Otherwise, I would suggest to:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;login to your rest directory&lt;/LI&gt;&lt;LI&gt;browser to the folder your are attempting to retrieve&lt;/LI&gt;&lt;LI&gt;add the &lt;EM&gt;?token=&lt;/EM&gt; parameter to the URL and navigate to the page, it should keep working&lt;/LI&gt;&lt;LI&gt;add the &amp;amp;f=json parameter to the URL and navigate again, it should keep working&lt;/LI&gt;&lt;LI&gt;change the token to invalidate it and navigate to the page, you should get an error object.&lt;/LI&gt;&lt;/OL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 25 Apr 2016 17:33:07 GMT</pubDate>
    <dc:creator>DavidBlanchard</dc:creator>
    <dc:date>2016-04-25T17:33:07Z</dc:date>
    <item>
      <title>Token validator</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/token-validator/m-p/334124#M30885</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hello,&lt;/P&gt;&lt;P&gt;I need to know if theres a way of validate the token once u saved it in localStorage.&lt;/P&gt;&lt;P&gt;Right now im creating tokens with a certain duration (lets say 1day) and using them directly on the webservice.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So i need to know once u save it in a localStorage var how to validate if the token is already expired or not.&lt;/P&gt;&lt;P&gt;I was thinking to do this through ajax but i cannot figure out how to do it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Until now i have something like this, i hope u guys can help me &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;function tokenValidator(t){

&lt;SPAN&gt;&amp;nbsp; const exampleUrl = "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fgisred.chilquinta.cl%3A5555%2Farcgis%2Frest%2Fservices%2FInterrupciones%2FPO%2FMapServer" target="_blank"&gt;http://myserver/arcgis/rest/services/mylayer/sufolder/MapServer&lt;/A&gt;&lt;SPAN&gt;";&lt;/SPAN&gt;
&amp;nbsp; const datat = {
&amp;nbsp;&amp;nbsp;&amp;nbsp; token: t
&amp;nbsp; };
&amp;nbsp; console.log(t);
&amp;nbsp; $.ajax({
&amp;nbsp;&amp;nbsp;&amp;nbsp; url: exampleUrl,
&amp;nbsp;&amp;nbsp;&amp;nbsp; dataType: 'json',
&amp;nbsp;&amp;nbsp;&amp;nbsp; data:&amp;nbsp; datat 
&amp;nbsp; })
&amp;nbsp; .done(isDone =&amp;gt; {


&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log(isDone);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("the token is still valid");


&amp;nbsp; })
&amp;nbsp; .fail(error =&amp;gt; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log(error);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("token is not valid, redirect to login page");
&amp;nbsp; });
}&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:49:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/token-validator/m-p/334124#M30885</guid>
      <dc:creator>EvelynHernandez</dc:creator>
      <dc:date>2021-12-11T15:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: Token validator</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/token-validator/m-p/334125#M30886</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You should also be storing the tokens expiration in the local storage, this would allow you to first check whether it is expired without making a network request.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As for validating with ArcGIS for Server/ArcGIS Online, try fetching the definition of a secured service of folder. For example:&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fwww.mydomain.com%2Farcgis%2Frest%2Fservices%2FsecuredService%2FFeatureServer%3Ff%3Djson%26token%3D%25token" rel="nofollow" target="_blank"&gt;https://www.mydomain.com/arcgis/rest/services/securedService/FeatureServer?f=json&amp;amp;token=%token&lt;/A&gt;&lt;SPAN&gt; goes here%&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the token isn't valid, you'll get the following response:&lt;/P&gt;&lt;P&gt;{"error":{"code":498,"message":"Invalid Token","details":[]}}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Apr 2016 17:12:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/token-validator/m-p/334125#M30886</guid>
      <dc:creator>DavidBlanchard</dc:creator>
      <dc:date>2016-04-22T17:12:45Z</dc:date>
    </item>
    <item>
      <title>Re: Token validator</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/token-validator/m-p/334126#M30887</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Oh thats true. I will try it and put the result here just in case if someone needs it.&lt;/P&gt;&lt;P&gt;About the ajax fetching the secured service folder, do u have any example for getting the "error" result? cuz i always get a "400" error.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Apr 2016 16:58:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/token-validator/m-p/334126#M30887</guid>
      <dc:creator>EvelynHernandez</dc:creator>
      <dc:date>2016-04-25T16:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: Token validator</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/token-validator/m-p/334127#M30888</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The only time I get a 400 error is when I have a malformed URL. Are you sure you have the parameters in the URL correctly set (starting with a question mark, separated by an ampersand)? Also, if you are sending a POST request instead of a GET request, the parameters need to be passed as data, not in the URL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Otherwise, I would suggest to:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;login to your rest directory&lt;/LI&gt;&lt;LI&gt;browser to the folder your are attempting to retrieve&lt;/LI&gt;&lt;LI&gt;add the &lt;EM&gt;?token=&lt;/EM&gt; parameter to the URL and navigate to the page, it should keep working&lt;/LI&gt;&lt;LI&gt;add the &amp;amp;f=json parameter to the URL and navigate again, it should keep working&lt;/LI&gt;&lt;LI&gt;change the token to invalidate it and navigate to the page, you should get an error object.&lt;/LI&gt;&lt;/OL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Apr 2016 17:33:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/token-validator/m-p/334127#M30888</guid>
      <dc:creator>DavidBlanchard</dc:creator>
      <dc:date>2016-04-25T17:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: Token validator</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/token-validator/m-p/334128#M30889</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry it was 200, not 400.&lt;/P&gt;&lt;P&gt;For example i have the following:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;function tokenValidator(){
&amp;nbsp; var t = localStorage.getItem('token');
&lt;SPAN&gt;&amp;nbsp; const exampleUrl = "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fmyserver%2Farcgis%2Frest%2Fservices%2Fmylayer%2Fmysub%2FMapServer" target="_blank"&gt;http://myserver/arcgis/rest/services/mylayer/mysub/MapServer&lt;/A&gt;&lt;SPAN&gt;";&lt;/SPAN&gt;
&amp;nbsp; const datas = {
&amp;nbsp;&amp;nbsp;&amp;nbsp; token: t
&amp;nbsp; };

$.ajax({
&amp;nbsp;&amp;nbsp;&amp;nbsp; method: "POST",
&amp;nbsp;&amp;nbsp;&amp;nbsp; url: exampleUrl,
&amp;nbsp;&amp;nbsp;&amp;nbsp; dataType: 'json',
&amp;nbsp;&amp;nbsp;&amp;nbsp; data: datas
&amp;nbsp; })
&amp;nbsp; .done(isDone =&amp;gt; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("token validator sucess", isDone);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //if my token is still valid i keep the main app.

&amp;nbsp; })
&amp;nbsp; .fail(error =&amp;gt; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("token validator failure", error);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //if i get the token is not valid i have to redirect my page to the login.
&amp;nbsp; });

}&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the console i have this:&lt;/P&gt;&lt;P&gt;token validator failure &lt;/P&gt;&lt;P&gt;object:&lt;/P&gt;&lt;P&gt;status: 200&lt;/P&gt;&lt;P&gt;statusText: ok&lt;/P&gt;&lt;P&gt;And i got the url where i want to access. But sometimes i got the login arcgis website.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:49:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/token-validator/m-p/334128#M30889</guid>
      <dc:creator>EvelynHernandez</dc:creator>
      <dc:date>2021-12-11T15:49:50Z</dc:date>
    </item>
    <item>
      <title>Re: Token validator</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/token-validator/m-p/334129#M30890</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try adding&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_1461609385102380 jive_text_macro" data-renderedposition="34_8_1155_16" jivemacro_uid="_1461609385102380"&gt;&lt;P&gt;f: "json"&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;to your &lt;EM&gt;datas&lt;/EM&gt; object. ArcGIS for Server usually defaults to HTML unless specified otherwise. This parameter will tell ArcGIS to serve the results as JSON (&lt;EM&gt;​f&lt;/EM&gt; stands for format).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Apr 2016 18:37:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/token-validator/m-p/334129#M30890</guid>
      <dc:creator>DavidBlanchard</dc:creator>
      <dc:date>2016-04-25T18:37:50Z</dc:date>
    </item>
    <item>
      <title>Re: Token validator</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/token-validator/m-p/334130#M30891</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok, it was that, Thanks for all ur help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I finished my quest doing this.&lt;/P&gt;&lt;P&gt;For controlling the token expiration i used an event for the dynamic service that i was accessing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example: my layer has a refreshInterval =1;&lt;/P&gt;&lt;P&gt;So, in every minute it will be refreshed, but what happen if the token that allows me to update it is already expired?&lt;/P&gt;&lt;P&gt;To solve that i used:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;interrClienteSED.on('update-end', (obj)=&amp;gt;{
&amp;nbsp;&amp;nbsp;&amp;nbsp; if(obj.error){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("Redirecting to login page, token for this session is ended...");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; window.location.href = "index.html";
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp; });&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So that will return an object that contains error if the update cannot be done or info if its still ok and it will be checking it every minute.&lt;/P&gt;&lt;P&gt;In my case i want to redirecto to the login page (index).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the case if i go directly to my secondary page (the page after the login), I have to see if the token is still valid, then i just use my ajax call:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;function tokenValidator(){
&amp;nbsp; var t = localStorage.getItem('token');
&lt;SPAN&gt;&amp;nbsp; const exampleUrl = "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fmyservice%2Farcgis%2Frest%2Fservices%2Fmylayer%2FMapServer" target="_blank"&gt;http://myservice/arcgis/rest/services/mylayer/MapServer&lt;/A&gt;&lt;SPAN&gt;";&lt;/SPAN&gt;
&amp;nbsp; const datas = {
&amp;nbsp;&amp;nbsp;&amp;nbsp; token: t,
&amp;nbsp;&amp;nbsp;&amp;nbsp; f: "json"
&amp;nbsp; };
&amp;nbsp; console.log("in token validator");
&amp;nbsp; $.ajax({
&amp;nbsp;&amp;nbsp;&amp;nbsp; method: "POST",
&amp;nbsp;&amp;nbsp;&amp;nbsp; url: exampleUrl,
&amp;nbsp;&amp;nbsp;&amp;nbsp; dataType: 'html',
&amp;nbsp;&amp;nbsp;&amp;nbsp; data: datas
&amp;nbsp; })
&amp;nbsp; .done(isDone =&amp;gt; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (isDone.indexOf('Invalid Token') &amp;gt;= 0){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("redirect to login page from token validator...");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; window.location.href = "index.html";
&amp;nbsp;&amp;nbsp;&amp;nbsp; }else{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("everything is ok! u can continue doing what u are doing.");
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp; })
&amp;nbsp; .fail(error =&amp;gt; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("token validator failure", error);
&amp;nbsp; });
}&lt;/PRE&gt;&lt;P&gt;I hope this helps to someone that has the same issue &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:49:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/token-validator/m-p/334130#M30891</guid>
      <dc:creator>EvelynHernandez</dc:creator>
      <dc:date>2021-12-11T15:49:53Z</dc:date>
    </item>
  </channel>
</rss>

