When attempting to create a portal user we are receiving an error message:
{
"error": {
"code": 500,
"message": "java.lang.Exception: The server at '<SERVER URL>' returned an error. Invalid token. []",
"details": null
}
}<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>I saw this message but adding the referer didn't make a difference. The set up is exactly the same except we are using 10.6.
https://community.esri.com/thread/212042-invalid-token-for-portaladminsecurityuserscreateuser
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">generate_portal_token</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> use_referer<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
url <SPAN class="operator token">=</SPAN> self<SPAN class="punctuation token">.</SPAN>portal_url <SPAN class="operator token">+</SPAN> self<SPAN class="punctuation token">.</SPAN>rest_path <SPAN class="operator token">+</SPAN> <SPAN class="string token">"/generatetoken"</SPAN>
payload <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">if</SPAN> use_referer<SPAN class="punctuation token">:</SPAN>
payload<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"client"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">"referer"</SPAN>
payload<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"referer"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> self<SPAN class="punctuation token">.</SPAN>portal_url
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
payload<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"client"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">"requestip"</SPAN>
payload<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"Username"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> self<SPAN class="punctuation token">.</SPAN>username
payload<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"Password"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> self<SPAN class="punctuation token">.</SPAN>password
payload<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"expiration"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="number token">60</SPAN>
payload<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"f"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">"json"</SPAN>
headers <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">'Content-Type'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"application/x-www-form-urlencoded"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'cache-control'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"no-cache"</SPAN>
<SPAN class="punctuation token">}</SPAN>
response <SPAN class="operator token">=</SPAN> requests<SPAN class="punctuation token">.</SPAN>request<SPAN class="punctuation token">(</SPAN>
<SPAN class="string token">"POST"</SPAN><SPAN class="punctuation token">,</SPAN> url<SPAN class="punctuation token">,</SPAN> data<SPAN class="operator token">=</SPAN>payload<SPAN class="punctuation token">,</SPAN> headers<SPAN class="operator token">=</SPAN>headers<SPAN class="punctuation token">,</SPAN> verify<SPAN class="operator token">=</SPAN><SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>response<SPAN class="punctuation token">.</SPAN>text<SPAN class="punctuation token">)</SPAN>
token_data <SPAN class="operator token">=</SPAN> json<SPAN class="punctuation token">.</SPAN>loads<SPAN class="punctuation token">(</SPAN>response<SPAN class="punctuation token">.</SPAN>text<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN> token_data<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"token"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN><SPAN class="keyword token">def</SPAN> <SPAN class="token function">create_portal_user</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> user<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
url <SPAN class="operator token">=</SPAN> self<SPAN class="punctuation token">.</SPAN>portal_url <SPAN class="operator token">+</SPAN> <SPAN class="string token">"/portaladmin/security/users/createUser"</SPAN>
referer_token <SPAN class="operator token">=</SPAN> self<SPAN class="punctuation token">.</SPAN>generate_portal_token<SPAN class="punctuation token">(</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN>
payload <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="punctuation token">}</SPAN>
payload<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"firstname"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> user<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"firstname"</SPAN><SPAN class="punctuation token">]</SPAN>
payload<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"lastname"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> user<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"lastname"</SPAN><SPAN class="punctuation token">]</SPAN>
payload<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"password"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> user<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"password"</SPAN><SPAN class="punctuation token">]</SPAN>
payload<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"level"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> user<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"level"</SPAN><SPAN class="punctuation token">]</SPAN>
payload<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"email"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> user<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"email"</SPAN><SPAN class="punctuation token">]</SPAN>
payload<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"role"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> user<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"role"</SPAN><SPAN class="punctuation token">]</SPAN>
payload<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"provider"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">"arcgis"</SPAN>
payload<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"description"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">"test user"</SPAN>
payload<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"f"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">"json"</SPAN>
payload<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"token"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> referer_token
payload<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"referer"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> self<SPAN class="punctuation token">.</SPAN>portal_url
headers <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">'Content-Type'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"application/x-www-form-urlencoded"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'cache-control'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"no-cache"</SPAN>
<SPAN class="punctuation token">}</SPAN>
response <SPAN class="operator token">=</SPAN> requests<SPAN class="punctuation token">.</SPAN>request<SPAN class="punctuation token">(</SPAN>
<SPAN class="string token">"POST"</SPAN><SPAN class="punctuation token">,</SPAN> url<SPAN class="punctuation token">,</SPAN> data<SPAN class="operator token">=</SPAN>payload<SPAN class="punctuation token">,</SPAN> headers<SPAN class="operator token">=</SPAN>headers<SPAN class="punctuation token">,</SPAN> verify<SPAN class="operator token">=</SPAN><SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>response<SPAN class="punctuation token">.</SPAN>text<SPAN class="punctuation token">)</SPAN>
response_data <SPAN class="operator token">=</SPAN> json<SPAN class="punctuation token">.</SPAN>loads<SPAN class="punctuation token">(</SPAN>response<SPAN class="punctuation token">.</SPAN>text<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN> response_data<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>If I don't use the referer then I get error 498 invalid token.
Any ideas what I am doing wrong?