The basic OAuth sample worked for me too. Basically I want to use the sample method for users to switch between secure mode and public view. For example, without login in, an anonymous user sees a non-editable public view layer that is a view of a protected editable feature layer which can then be added and edited if user with proper permission signs in.
The bug comes up when you build on the sample with more functionality. After signing in, the portal loads. I see a fully populated portal object, with all the right properties , except for portal.user is null. IdentityManager.checkSignedInStatus returns a credential in Session Storage. If you replace portal.user.username with credential.userId you can even do a PortalQuery and list your AGOL items like the sample does. The token is valid because I can string it behind a secure service URL and open the REST endpoint. But my AGOL secure layer that I want to add to a map (after signedInStatus checked and portal loads) fails to load.
I did not want to "pre-load" the secure, editable layer by default and prompt every user to login immediately upon opening the web page. I did discover that if you set esriConfig.request.useIdentity=false at the start of require() it will produce this bug. Obviously there are probably other conflicting configs or custom modules in my app that created this issue, and I am now forced to go through my entire source code to debug it. I was just wondering if this is a situation that others might have encountered.