arcgis javascript display private webmap without popup dialog.

1291
8
Jump to solution
04-19-2018 08:04 AM
weironglin1
New Contributor

My project was switch the webmap from public to private and it's pop up the box to ask for login. How can I bypass the dialog box and use the username, password to authenticate inside my app? I know in swift application or objective C, we can use the portal credential to login automatically. But inside javascript there is no such setting, any help?

0 Kudos
1 Solution

Accepted Solutions
8 Replies
RobertScheitlin__GISP
MVP Emeritus
0 Kudos
weironglin1
New Contributor

Is Resource Proxy is only for secure layer and features? Does the proxy support private webmap? I set up a nodejs version of the proxy server But it did not work.Any code example that can help me better understand the settings. Thank you.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Did the first like not help with that?

0 Kudos
weironglin1
New Contributor

I'm sure the proxy can help resolve the issues, but right now I only have is the map ID, an usename and password. I testing it using Nodejs proxy resource code but it still pop up the login box. Dose Arcgis has some working example that might be very helpful. Thank you.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Weirong,

   So you should know your orgs URL and the user name an password. That is all that is needed to configure the proxy.config file.

Here is an example:

<?xml version="1.0" encoding="utf-8" ?>
<ProxyConfig allowedReferers="*" mustMatch="true" logFile="proxylog.txt">
    <serverUrls>
        <serverUrl url="https://www.arcgis.com" matchAll="true"/>
        <serverUrl url="http://yourOrgName.maps.arcgis.com" matchAll="true" />
        <serverUrl url="http://yourOrgName.maps.arcgis.com/sharing/rest" matchAll="true" username="x" password="******" />
    </serverUrls>
</ProxyConfig>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

And in the first link I provided follow step 12:

  1. The following steps demonstrate how to configure the proxy in your JavaScript application. There are a couple of ways to configure the proxy inside of a JavaScript application. For this particular example, we use the proxy rule.
  • In the JavaScript application, add two proxy rules:
    esri.addProxyRule({urlPrefix: "http://route.arcgis.com", proxyUrl:"http://<yourServer>/<pathToProxy>/proxy.ashx" });

    esri.addProxyRule({   urlPrefix: "http://traffic.arcgis.com", proxyUrl: "http://<yourServer>/<pathToProxy>/proxy.ashx" });
  • As another possibility, add the "esri/urlUtils" module in the require statement, and add the following rule:                                                                                                           urlUtils.addProxyRule(urlPrefix: "route.arcgis.com", proxyUrl: "http://<yourServer>/<pathToProxy>/proxy.ashx" });urlUtils.addProxyRule({urlPrefix: "traffic.arcgis.com", proxyUrl: "http://<yourServer>/<pathToProxy>/proxy.ashx"});  
  • Here is another way to configure the proxy.
    esriConfig.defaults.io.proxyUrl = "<url_to_proxy>"
    esriConfig.defaults.io.alwaysUseProxy = false; The proxyUrl is the path to your proxy page hosted on IIS.
0 Kudos
weironglin1
New Contributor

I follow exactly step by step and the login box still pop up. See the below for my details implementation, any suggestions for the settings? Thank you.

here is my config.json

{
"url":"https://www.arcgis.com","matchAll":true
},
{
"url": "http://wretetw.maps.arcgis.com", "matchAll":true
},
{
"matchAll": true,
"username":"username",
"password":"password"
},

 and my javascript file to display the web map.

<script>
        require([
        "esri/urlUtils",
         "esri/map",
         "esri/arcgis/utils",
         "esri/dijit/Legend",
         "esri/SpatialReference",
         "esri/geometry/Point",
         "esri/symbols/SimpleMarkerSymbol",
         "esri/graphic",
         "dojo/domReady!"
         ], function(urlUtils,Map, arcgisUtils, Legend, SpatialReference, Point, SimpleMarkerSymbol, Graphic){
            urlUtils.addProxyRule({
           urlPrefix: "http://wretetw.maps.arcgis.com",
            proxyUrl: "http://localhost:3692/proxy"
            });
            arcgisUtils.createMap("item number", "mapDiv").then(function (response) {
            map = response.map;
           
         });
        });
</script>
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

OK. I have re-read some of your replies and the Proxy that I am talking about and provided a link for does not have a Node version. You should download the Resource Proxy I gave a link to in my previous replies and then follow the instructions I provided already.

weironglin1
New Contributor

The information are very helpful, thank you. I generate the token use the link.

https://www.arcgis.com/sharing/generateToken?f=json&request=gettoken&username=username&password=pass...

token format:

var token = {"server":"http://www.arcgis.com/share/rest","userId":"userId","token":"token str","expires":number,"ssl"::false}

call register token before create map

esriId.registerToken(token);

0 Kudos