AnsweredAssumed Answered

invalid token for portaladmin/security/users/createUser

Question asked by Sunvialley on Mar 28, 2018
Latest reply on Mar 29, 2018 by Sunvialley

Hi Everybody,

 

we have Portal for ArcGIS 10.5.1 (federated with AGS 10.5.1).

 

I try to use REST API to manage users in .net console application (using RestSharp).

 

To do that, I get a token on "https://{myAliasPortal}/arcgis/sharing/rest/generateToken"

Then I check if my user exists with "https://{myAliasPortal}/arcgis/sharing/rest/community/users/{usermame}"  (it's work)

Then I want to add user with "https://{myAliasPortal}/arcgis/portaladmin/security/users/createUser" and I have this error :

 

{"error":{"code":500,"message":"java.lang.Exception: The server at 'https://{machineName}:7443/arcgis/sharing/rest/community/createUser' returned an error. Invalid token. []","details":null}}

 

It's a code 500 (not a 498).

It's strange because the server url returned :

  • has machine name and port instead of aliasName (webAdaptor)
  • is mixed with "sharing/rest" and "portaladmin" url (for me, "createUser" exist only on portaladmin and not on sharing/rest).
  • java error, not a direct rest API error ?

 

Do you have idea to fix the problem please ?

 

 

Please find bellow the code :

 

static string getToken(string username, string password, string geoportalUrl)
{
   RestClient client = new RestClient(geoportalUrl);
   RestRequest request = new RestRequest("arcgis/sharing/rest/generateToken", Method.POST);
   request.AddParameter("f", "json");
   request.AddParameter("username", username);
   request.AddParameter("password", password);
   request.AddParameter("client", "referer");
   request.AddParameter("referer", geoportalUrl + "/arcgis");
   IRestResponse response = client.Execute(request);
   var content = response.Content;
   ArcGISToken t = JsonConvert.DeserializeObject<ArcGISToken>(content.ToString());
   return t.token;
}

 

static PortalUser createUser(string username, string firstname, string lastname, string role,
                                              string level, string email, string provider,
                                              string geoportalUrl, string token)
{
   RestClient client = new RestClient(geoportalUrl);
   RestRequest request = new RestRequest("arcgis/portaladmin/security/users/createUser", Method.POST);
   request.AddParameter("username", username);
   request.AddParameter("firstname", firstname);
   request.AddParameter("lastname", lastname);
   request.AddParameter("role", role);
   request.AddParameter("level", level);
   request.AddParameter("email", email);
   request.AddParameter("provider", provider); //"enterprise"
   request.AddParameter("token", token);
   request.AddParameter("f", "json");
   IRestResponse response = client.Execute(request);
   var content = response.Content;
}

and the call :

string adminUsername = "adminaccount";
string adminPassword = "password";

string geoportalUrl = "https://geoportal.company.com";

string token = getToken(adminUsername, adminPassword, geoportalUrl);

createUser("JOHNDOE", "John", "Doe", "viewer","1", "john.doe@company.com", "enterprise", geoportalUrl, token);

 

Thanks in advance for your help.

 

 

Edit : if I generate token with 

request.AddParameter("client", "requestip");

I get this error :

{"error":{"code":498,"message":"Invalid Token.","details":["Token would have expired, regenerate token and send the request again.","If the token is generated based on the referrer make sure the referrer information is available with every request in header."]}}

Outcomes