Javascript API Note getting token wit proxy.

1642
5
02-21-2018 03:25 AM
cadgism
Occasional Contributor

I have configured  proxy and trying to consume a secured layer through proxy in Arcgis javascript.

When I test  the proxy manually i get the response  in web browser. That is to to say,  when I enter the following Url in the broweser it returns a valid token :-

Token:

QBh62mCJxxyyXXyyCCCVVOdfDopSvrUX_4qq7IcMcpz2-U‍‍

  URL :

http://localhost/DotNet/proxy.ashx?http://00.00.00:6080/arcgis/tokens?request=gettoken&username=user&password=123&‍‍‍‍

 

But through Javascript , gives an error :

 dojo.io.script error Error: Token Required‍‍‍

Javascript :

 esriConfig.defaults.io.proxyUrl = "http://localhost/DotNet/proxy.ashx";
 esri.config.defaults.io.alwaysUseProxy = false;

urlSecuredlayer = "http://00.00.00.00:6080/arcgis/rest/services/myQuery/mylayer/MapServer/0";
Securedlayer = new esri.layers.FeatureLayer(urlSecuredlayer, { id: "urlSecuredlayer", mode: esri.layers.FeatureLayer.MODE_ONDEMAND, outFields: ["*"] });
 
    tiledLayer1 = new ArcGISTiledMapServiceLayer(urlsatellite, { id: "SatelitteMap" });
    app.map.addLayer(tiledLayer1);

    var states_Symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,  
                   new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,   
                   new dojo.Color([255, 32, 255, 0.35]), 1),  
                   new dojo.Color([255, 65, 125, 0.35]));

    urlSecuredlayer.setRenderer(new esri.renderer.SimpleRenderer(states_Symbol));
    app.map.addLayers([Securedlayer]);
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thank you for any help.

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus

cadegis,

   Do you have a rule in your proxy.config for your 

http://00.00.00.00:6080/
0 Kudos
cadgism
Occasional Contributor

Thank You Robert Scheitlin, GISP

My proxy.config file :-

<?xml version="1.0" encoding="utf-8" ?>
<ProxyConfig allowedReferers="*"             
          mustMatch="false">    

<serverUrls>        

<serverUrl url="http://00.00.00.00:6080/arcgis/rest/services/myQuery/mylayer/MapServer/0"
     matchAll="false"                                    
     host="http://localhost/"                                    
     userName="user"                                     
     password="123">     
</serverUrl>     

</serverUrls>

</ProxyConfig>



<!-- See https://github.com/Esri/resource-proxy for more information -->‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

cadgis,

   Your proxy.config should use a less specific url.

<?xml version="1.0" encoding="utf-8" ?>
<ProxyConfig allowedReferers="*"             
          mustMatch="false">    
  <serverUrls>        
    <serverUrl url="http://00.00.00.00:6080/arcgis/rest/services/myQuery"
       matchAll="true"                                                                       
       username="user"                                     
       password="123">     
    </serverUrl>     
  </serverUrls>
</ProxyConfig>
<!-- See https://github.com/Esri/resource-proxy for more information -->‍‍‍‍‍‍‍‍‍‍‍‍

Also usename is all lower case you had userName.

cadgism
Occasional Contributor

No Luck..Still not working,  producing same error...

0 Kudos
cadgism
Occasional Contributor

Solved. The solution was as follow:-

In Arcgis server all my services were configured as " HTTP and HTTPS " ,  when I changed it to "HTTP Only" it worked as it should. 

You were right about the " userName" , it should be "username" . 

The 'url' did not make any difference.

Thank You , Robert Scheitlin, GISP