when add a ArcGIS server on federated server on a portal for arcgis i have this issue "Unknown resource - could not find token service endpoint."
Just in case anyone runs into this problem...worked with Esri and all I had to do was clear my browser cookies.
I have this exact situation and just noting that clearing browser cookies did not work in my case.
In my case I'm getting the error when calling IdentityManager getCredentials.