I am trying to create a single sign on module for my company within Magento. I've set up a connection to the OAuth guarded server and managed to log in on the authentication server.
What I would like to do now is create an admin user in Magento if one doesn't exist with the retrieved username. If there is an administrator user with the given username then I want to log them in.
Currently I'm having trouble finding the administraot user object by username. I've found the following code:
/** @var \Magento\User\Model\User $user */
$user = $this->_objectManager->get('Magento\User\Model\User')->loadByUsername('username');
Which returns an object regardless of the username I enter but the object doesn't seem to contain any usable administrator data.
Concretely my question is: how do I retrieve the user/admin model by its username and how do I verify if that model actually contains a user/admin object which I use to log in.