Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using with non-federated (standalone) servers not associated to portal #604

Closed
green3g opened this issue Jul 24, 2019 · 10 comments
Closed

Comments

@green3g
Copy link
Contributor

green3g commented Jul 24, 2019

Is it possible to use this library with standalone servers for making basic rest requests against a standalone arcgis server? Meaning not federated or trusted by any portals, I just want to generate an arcgis server token and make requests against the endpoints.

I'm running into errors thrown in this library that say the server cannot be trusted since its not a federated server...etc I am hoping someone here may know more about this.

@patrickarlt
Copy link
Contributor

You should be able to follow the flow of this here https://github.com/Esri/arcgis-rest-js/blob/master/packages/arcgis-rest-auth/src/UserSession.ts#L825-L900. But if you don't want to parse the code here is what we are doing:

  1. We make a request to the servers /rest/info endpoint
  2. We check for response.owningSystemUrl to see if the server is federated with a portal
  3. If there is no response.owningSystemUrl we check for response.authInfo and use it to generate the token
  4. If both 2 and 3 are false (no owningSystemUrl or authInfo) we can't automate authentication because the server doesn't advetise a portal or token endpoint.

I'm going to guess that you just have a configuration of server that we haven't encountered before. Could you do the following to help us debug:

  1. Post the contents of your servers rest/info endpoint here https://developers.arcgis.com/rest/services-reference/server-info.htm.
  2. Provide some sample code as to how you are using this? You can obscure URLs/usernames/passwords but it would be helpful to debug this.

@jgravois
Copy link
Contributor

see #423

@COV-GIS
Copy link
Contributor

COV-GIS commented Jul 24, 2019

You can use generateToken() directly against the server token endpoint using a built-in server user where the the token url is something like https://<server>/arcgis/tokens/generateToken. Or just use request() with the url and appropriate generateToken params. Then include the token with your other requests.

@green3g
Copy link
Contributor Author

green3g commented Jul 26, 2019

Thanks for all the info guys. I have the method that @COV-GIS mentioned working. I'm going to investigate further to see why I was encountering the error. I'll follow up with more details shortly

@green3g
Copy link
Contributor Author

green3g commented Jul 26, 2019

@patrickarlt here's my json. I don't believe there's anything special about this, I was probably just incorrectly using the library.

{
  "currentVersion": 10.71,
  "fullVersion": "10.7.1",
  "soapUrl": "https://services.wsbeng.com/arcgis/services",
  "secureSoapUrl": null,
  "authInfo": {
    "isTokenBasedSecurity": true,
    "tokenServicesUrl": "https://services.wsbeng.com/arcgis/tokens/",
    "shortLivedTokenValidity": 480
  }
}

@green3g
Copy link
Contributor Author

green3g commented Jul 26, 2019

Okay - here's what I'm doing to get that error:

    const authentication = new UserSession({
        server: arcgis.url,
        username: arcgis.username,
        password: arcgis.password,
        tokenDuration: arcgis.tokenExpires,
    });

    const defaultParams = { ...DEFAULT_PARAMS };
    console.log(defaultParams);

    const layerProps = config.featureLayer;
    const layerUrl = `${layerProps.url}/FeatureServer/${layerProps.layerId}`;
    
    // I think we need to do this in order to use the authentication in requests?
    await authentication.getToken(layerUrl);

//...further down

    const deleteResult = await request(`${layerUrl}/deleteFeatures`, {
        authentication,
        httpMethod: 'POST',
        params: {
            ...defaultParams,
            where,
        }
    });

This throws 'NOT_FEDERATED: https://services.wsbeng.com/arcgis/rest/services/wsb/projects/FeatureServer/4 is not federated with any portal and is not explicitly trusted.'

@jgravois
Copy link
Contributor

// I think we need to do this in order to use the authentication in requests?
await authentication.getToken(layerUrl);

that isn't necessary. anytime you pass authentication in a normal request, we will fetch a token and cache it.

what is arcgis.url in your code snippet?

@green3g
Copy link
Contributor Author

green3g commented Jul 26, 2019

Its just the arcgis server root: https://services.wsbeng.com/arcgis/.

@green3g
Copy link
Contributor Author

green3g commented Jul 26, 2019

Funny I got it working. I just removed the last slash. I'm tired today and can't follow the docs. I just looked over them again and saw that you guys don't pass the last slash and that's what did it for me.

Thanks for the troubleshooting guys!

@green3g green3g closed this as completed Jul 26, 2019
@jgravois
Copy link
Contributor

not your fault.

const [root] = url.split(/\/rest(\/admin)?\/services(?:\/|#|\?|$)/);

should be:

const [root] = cleanUrl(url).split(/\/rest(\/admin)?\/services(?:\/|#|\?|$)/)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants