This code is using the admin location to grab a Token. ERSI ArcGIS Online and other services use the 'public' url to get a token. On a secured server, the admin token url may not be available, but I think the 'public' one always is. The public one is at: "arcgis/tokens/generateToken" instead of "arcgis/admin/generateToken" as per: https://developers.arcgis.com/rest/services-reference/enterprise/generate-token.htm
This code is using the admin location to grab a Token. ERSI ArcGIS Online and other services use the 'public' url to get a token. On a secured server, the admin token url may not be available, but I think the 'public' one always is. The public one is at: "arcgis/tokens/generateToken" instead of "arcgis/admin/generateToken" as per: https://developers.arcgis.com/rest/services-reference/enterprise/generate-token.htm
Also, we can get iformation from the server info url, even on a server where directory services is disabled: https://developers.arcgis.com/rest/services-reference/enterprise/server-info.htm
https://my.host.com/instance_name/rest/info?f=pjson
A json return looks like:
This info will be good for checking the intial validity.