Esri / geoform-template-js

GeoForm is a configurable template for form based data editing of a Feature Service.
http://esri.github.io/geoform-template-js/
Apache License 2.0
67 stars 83 forks source link

DotNet Proxy isn't working #538

Closed randomblink closed 6 years ago

randomblink commented 6 years ago

I've configured the GeoForm per ALL instructions. But the proxy isn't working. The geoform is on an INTERNAL ONLY server. The AGOL Feature Layer and WebMap and Application are all shared with the Organization. I've got ClientID and ClientSecret setup in the proxy.

Nothing... it asks for sign on everytime.

driskull commented 6 years ago

hey @randomblink I think this comment might be what you need.

myTemplate.startup().then(function (config) {
                urlUtils.addProxyRule({
                urlPrefix: "prefixToServiceUrl",  // Does this look right? This is what worked when testing with AppBuilder
                proxyUrl: config.proxyurl
                });

https://developers.arcgis.com/javascript/3/jsapi/esri.urlutils-amd.html#addproxyrule

Basically, you need to tell esri.urlUtils to use your proxy for a specific URL.

Let me know if that works and that is it and I'll update the readme to cover this.

-Matt

randomblink commented 6 years ago

Here's my problem... I'm not sure what I need to use for the 'prefixToServiceUrl' entry... Here is the rest service url : https://cityoftulsa.maps.arcgis.com/sharing/rest/content/items/1e312d06f3f44867b970bc281c8e6357

Here is the url to the AGOL Application: http://cityoftulsa.maps.arcgis.com/home/item.html?id=1e312d06f3f44867b970bc281c8e6357

Since we host the Rest Service on our own ESRI Server should I point to the rest service directly? AND how should I configure the Proxy rule in the Proxy.config file?

randomblink commented 6 years ago

For an example:

I entered the following...

index.html

    require(["config/templateConfig", "application/template", "application/main", "esri/urlUtils"], function (templateOptions, Template, Main, urlUtils) {

and

          urlUtils.addProxyRule({
              urlPrefix: "https://cityoftulsa.maps.arcgis.com/sharing/rest/content/items/1e312d06f3f44867b970bc281c8e6357",  
              proxyUrl: config.proxyurl
            });               

Then I added to the proxy config like so...

proxy.config

  <serverUrl  url="https://cityoftulsa.maps.arcgis.com/sharing/rest/content/items/1e312d06f3f44867b970bc281c8e6357" 
              clientId="ClientIDGoesHere" clientSecret="ClientSecretGoesHere" 
                oauth2Endpoint="https://cityoftulsa.maps.arcgis.com/sharing/oauth2/" matchAll="true"/>

But it does not work...

driskull commented 6 years ago

hey @randomblink,

The URL prefix should be the URL to the rest service, not the portal item like I see above. It should only be a partial URL up to the service so that it can perform queries on the service and be able to identify that it should use the proxy.

For example the following prefix would proxy anything after /

https://services1.arcgis.com/XLY7M6F9oPzjvKmJ/ArcGIS/rest/services/Bruxelles_metro_lines/

So this would work:

https://services1.arcgis.com/XLY7M6F9oPzjvKmJ/ArcGIS/rest/services/Bruxelles_metro_lines/FeatureServer/0/query?f=json&outFields=Type%2COBJECTID&outSR=102100&returnGeometry=false&spatialRel=esriSpatialRelIntersects&where=(UPPER(Type)%20LIKE%20%27%25RED%25%27)

Everything else you have looks good.

randomblink commented 6 years ago

The current rest service that this is feeding from is located on our ArcServer. http://maps.cityoftulsa.org/gis/rest/services/LGDM/Address/FeatureServer/0

When I use that URL the geoform still doesn't work.

image

When I hover of the App ID in the login form I get the following URL. https://cityoftulsa.maps.arcgis.com/sharing/rest/content/items/1e312d06f3f44867b970bc281c8e6357

But using that URL the geoform still doesn't work.

driskull commented 6 years ago

Can you see if the network tab is using the proxy when calling for the service? That's a good first step. If not, make sure you have the proxyUrl set int he config.js as well.

If that doesn't work, try adding proxy rules for the rest URL without the http/https. like so:

urlUtils.addProxyRule({
  urlPrefix: "route.arcgis.com",
  proxyUrl: "<url_to_proxy>"
});
randomblink commented 6 years ago

Ok... So in Index.html I have the following... image

In the proxy.config I have the following... image

Is this what you meant by the service URL? And it doesn't matter if I leave the https:// or not. It still asks for login.

driskull commented 6 years ago

Yeah I don't think that will work. I think you need the actual URL to the rest service, not to the portal item.

For example:

{
            "serverUrl" : [
                {
                    "url": "http://route.arcgis.com",
                    "oauth2Endpoint": "https://www.arcgis.com/sharing/oauth2",
                    "clientId": "6Xo1d-example-9Kn2",
                    "clientSecret": "5a5d50-example-c867b6efcf969bdcc6a2",
                    "rateLimit": "120",
                    "rateLimitPeriod": "60",
                    "matchAll": true
                }
            ]
        },

So in the index addProxyRule, you need a partial match to the service URL, not the portal item and in the proxy.config you need the same for the url.

driskull commented 6 years ago

You should be able to go to the item in your portal and view the service URL to the rest service.

randomblink commented 6 years ago

Even if the service URL is on an ArcServer and not AGOL?

randomblink commented 6 years ago

http://maps.cityoftulsa.org/gis/rest/services/LGDM/Address/FeatureServer/0

driskull commented 6 years ago

yeah, like that... so the partial would be: maps.cityoftulsa.org/gis/rest/services/LGDM/Address/FeatureServer/0

driskull commented 6 years ago

We'll get this working :)

If I cant get it working ill find someone who will

randomblink commented 6 years ago

Did the partial in index.html, no go. Used the partial in the proxy.config, no go. Thank you so much. I tried to open a support ticket with ESRI yesterday and they still haven't called me back... this is a lifesaver.

driskull commented 6 years ago

I think the best thing to do now would be to start debugging it. Open up the console and network tab and see what URL is prompting the identity manager to request credentials. Maybe post a screenshot of the network tab and we can see if its even going through the proxy or if it is going through it but the credentials aren't working.

randomblink commented 6 years ago

Here is the CONSOLE tab... https://youtu.be/O8rUfCFSXtM

Here is the NETWORK tab... https://youtu.be/soDZSF5LGL4

I'm not seeing anything...

randomblink commented 6 years ago

It doesn't look like the proxy is even looked at. Which is frustrating. But seems apropos.

driskull commented 6 years ago

Yes, it looks like its the org item that is prompting the proxy.

So we need another entry for that in the proxy config.

{
            "serverUrl" : [
                {
                    "url": "maps.cityoftulsa.org/gis",
                    "oauth2Endpoint": "https://cityoftulsa.maps.arcgis.com/sharing/oauth2",
                    "clientId": "INSERT",
                    "clientSecret": "INSERT",
                    "matchAll": true
                }
            ]
        },

And add another proxy rule:

urlUtils.addProxyRule({ urlPrefix: "maps.cityoftulsa.org/gis", proxyUrl: "" });

randomblink commented 6 years ago

Added those both and got the same... https://youtu.be/kf2_1oLH4oI

randomblink commented 6 years ago

Index.html setup image

randomblink commented 6 years ago

proxy.config setup image

driskull commented 6 years ago

In the network tab, click on the ?self= links and see what URL is prompting the username/password. note if its calling self with HTTP vs HTTPS. If its using https, you'll need to use https in the proxy.config as well.

screen shot 2017-10-10 at 11 08 55 am

Also make sure that in your app in the config.js the proxyurl is entered to point to your proxy on your server. Can you send a screen of that?

randomblink commented 6 years ago

default.js setup image

First self?f=... image

Second / Last self?f=... image

randomblink commented 6 years ago

I tried adding in those urls... https://cityoftulsa.maps.arcgis.com/sharing/rest https://www.arcgis.com/sharing/rest https://maps.cityoftulsa.org/gis https://maps.cityoftulsa.org/gis/rest/services/LGDM/Address/FeatureServer/0

Both to index.html and proxy.config with no luck.

driskull commented 6 years ago

Can you share the network request for the item beginning with "1e..." Is that trying to go through the proxy at all?

randomblink commented 6 years ago

image

randomblink commented 6 years ago

Does not appear to be trying to go through the proxy.

randomblink commented 6 years ago

Wait... the RESPONSE for this entry shows the following.

{"error":{"code":403,"messageCode":"GWM_0003","message":"You do not have permissions to access this resource or perform this operation.","details":[]}}

driskull commented 6 years ago

yes, but its not prompting the proxy. So add another proxyrule for cityoftulsa.maps.arcgis.com/sharing/rest/content/items/<ITEMID>

driskull commented 6 years ago

Also make sure the proxy.config has an entry for https://cityoftulsa.maps.arcgis.com

^ make sure its https. Might be good to have one for http and https.

Once the proxy is being prompted than we can work on getting the proxy to handle credentials. First step is to get it redirecting the URL to the proxy.

randomblink commented 6 years ago

index.html image

proxy.config image

randomblink commented 6 years ago

Still not working

driskull commented 6 years ago

Make sure to add the proxyRule before the myTemplate.startup() here:

https://user-images.githubusercontent.com/235770/31399077-a9836d5a-adb0-11e7-8f90-197574b1c84a.png

driskull commented 6 years ago

I'm thinking the item is being requested before the proxyRule is in effect

randomblink commented 6 years ago

Ok... https://youtu.be/qoWKnhxkYtA

We might be getting closer.

driskull commented 6 years ago

Yes! some progress. It is going to the proxy now but credentials arent working. So now we just need to get the proxy.config to pass the correct credentials to the correct urls.

The clientId and clientSecret are valid right? And the Urls are matching? Make sure that urls have both http and https if a request is going via http.

driskull commented 6 years ago

Looks like the item one isn't returning anything. it should return data for the item.

randomblink commented 6 years ago

ClientID and ClientSecret are good... The URLS are matching.

index.html after adjustments image

proxy.config after adjustments image

default.js setup image

I have the appid but not the mapid... Should I adjust that?

randomblink commented 6 years ago

I'll be back to this later. I have to eat. It's almost 2:30pm here. Sorry.

randomblink commented 6 years ago

Ok... I have returned.

driskull commented 6 years ago

Just need to figure out which URL is not returning the data needed and then add it to the proxy config to pass authentication through.

randomblink commented 6 years ago

I think it's this one: https://cityoftulsa.maps.arcgis.com/sharing/rest/content/items/1e312d06f3f44867b970bc281c8e6357

But at this point I'm so lost...

driskull commented 6 years ago

What is the "sharinghost": "https://www.arcgis.com", in the config? it should be "sharinghost": "https://cityoftulsa.maps.arcgis.com",

randomblink commented 6 years ago

image

driskull commented 6 years ago

looks good...

I have the appid but not the mapid... Should I adjust that?

No that should be fine.

I'm lost too :(

randomblink commented 6 years ago

I'm adding the mapid.

randomblink commented 6 years ago

image

image

403... GWM_0003

driskull commented 6 years ago

It looks like in your proxy.config you're using username and clientSecret. I think it should be clientId and clientSecret no?

driskull commented 6 years ago

or you use username and password in there.

randomblink commented 6 years ago

No I had tried a few combinations... It should be clientId and clientSecret I fixed it... Now I am getting this... image