Closed randomblink closed 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
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?
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...
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.
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.
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.
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>"
});
Ok... So in Index.html I have the following...
In the proxy.config I have the following...
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.
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.
You should be able to go to the item in your portal and view the service URL to the rest service.
Even if the service URL is on an ArcServer and not AGOL?
yeah, like that... so the partial would be: maps.cityoftulsa.org/gis/rest/services/LGDM/Address/FeatureServer/0
We'll get this working :)
If I cant get it working ill find someone who will
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.
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.
Here is the CONSOLE tab... https://youtu.be/O8rUfCFSXtM
Here is the NETWORK tab... https://youtu.be/soDZSF5LGL4
I'm not seeing anything...
It doesn't look like the proxy is even looked at. Which is frustrating. But seems apropos.
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: "
Added those both and got the same... https://youtu.be/kf2_1oLH4oI
Index.html setup
proxy.config setup
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.
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?
default.js setup
First self?f=...
Second / Last self?f=...
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.
Can you share the network request for the item beginning with "1e..." Is that trying to go through the proxy at all?
Does not appear to be trying to go through the proxy.
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":[]}}
yes, but its not prompting the proxy. So add another proxyrule for cityoftulsa.maps.arcgis.com/sharing/rest/content/items/<ITEMID>
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.
index.html
proxy.config
Still not working
Make sure to add the proxyRule before the myTemplate.startup()
here:
https://user-images.githubusercontent.com/235770/31399077-a9836d5a-adb0-11e7-8f90-197574b1c84a.png
I'm thinking the item is being requested before the proxyRule is in effect
Ok... https://youtu.be/qoWKnhxkYtA
We might be getting closer.
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.
Looks like the item one isn't returning anything. it should return data for the item.
ClientID and ClientSecret are good... The URLS are matching.
index.html after adjustments
proxy.config after adjustments
default.js setup
I have the appid but not the mapid... Should I adjust that?
I'll be back to this later. I have to eat. It's almost 2:30pm here. Sorry.
Ok... I have returned.
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.
I think it's this one: https://cityoftulsa.maps.arcgis.com/sharing/rest/content/items/1e312d06f3f44867b970bc281c8e6357
But at this point I'm so lost...
What is the "sharinghost": "https://www.arcgis.com",
in the config? it should be "sharinghost": "https://cityoftulsa.maps.arcgis.com",
looks good...
I have the appid but not the mapid... Should I adjust that?
No that should be fine.
I'm lost too :(
I'm adding the mapid.
403... GWM_0003
It looks like in your proxy.config you're using username
and clientSecret
. I think it should be clientId
and clientSecret
no?
or you use username
and password
in there.
No I had tried a few combinations... It should be clientId and clientSecret
I fixed it... Now I am getting this...
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.