I'm trying to include a feature layer in a web map in Portal, but when I add the layer Portal asks for my server credentials. The service is not secure but I can cancel the pop up and add the layer. However, when I share the web map as a web application I get an invalid token error. Portal and Server are on the same machine and both are using https. Maybe there is a configure error somewhere? Any help is appreciated.
Are Portal and Server federated? Do they use the same web adaptor, or different ones? Can you check the requests using Fiddler or your browsers developer tools and figure out which specific request receives a response that indicates a sign-in or some type of authentication is required?
Not federated (although we are considering it). Appear to be on same web adaptor. It looks like it might be the initial query request for the feature layer that triggers the authentication and invalid token error.
The first thing you should do is install another web adaptor with a different name, and configure either Portal or Server with it. Using the same web adaptor for both is not supported, see here for more info.
We've configured Portal with a different web adaptor with a different name and imported the existing SSL certificate. Everything is pointing correctly, but I'm still getting the server credential request when the layer is added to a web map and an invalid token error in a published web application. Portal is still not federated with Server.
Turns out there was a bug associated with my issue
[BUG-000086352: If Portal for ArcGIS and ArcGIS for Server are hosted on the same machine but not federated and a user is signed in to Portal for ArcGIS, a web map containing unsecured map service feature layers prompts user for credentials.]
Apparently, the problem is fixed in 10.4 so we're looking at doing an early upgrade to 10.4.1.