When I have to add in a service that requires signing in with my organization creditentials, I have to use OAuthInfo as well as IdentityManager, like this
require([...,
"esri/identity/OAuthInfo",
"esri/identity/IdentityManager",
...
], function (..., OAuthInfo, identityManager, ...) {
const portalUrl = 'your portal url';
const info = new OAuthInfo({
appId: "xxxxxxxxxxxxxxxx", //*** Your Client ID value goes here ***//
popup: false // inline redirects don't require any additional app configuration
});
identityManager.registerOAuthInfos([info]);
// send users to arcgis.com to login
identityManager.getCredential(portalUrl);
identityManager.checkSignInStatus(portalUrl).then(function () {
layer = new FeatureLayer({
portalItem: {
id: "your item"
},
outFields: ["*"]
});
.
.
.
});