Use OC\User\Session

We are try make owncload app.
App is Automatic user creation and login.
When we want to use OC\User\Session it gives the following error.

Could not resolve OC\Authentication\Token\IProvider! Class can not be instantiated or error resolving constructor arguments: Could not resolve CustomController

Unfortunately, you gave far too little info how you tried to achieve your goal.

I think, you’ll have to use the Provisioning API for this.

We have a Customer B2B Portal.
When we click on a link I will create here, we are trying to create a user on OwnCloud and have him log in automatically.
I created a user but I can’t login.
Example Link: owncloud.mydomain/index.php/apps/users-example/login/username

This information is useless because no one here can know what is behind the endpoint of your app.

EDIT: Maybe you should describe your goal more clearly.
And possibly show some relevant parts of your code.

if ($user->isEnabled()) {

		if (!$this->userSession->isLoggedIn()) {
			try {
				$this->userSession->login($username, $password);

				$this->userSession->createSessionToken($this->request, $user->getUID(), $user->getUID(), $password);

				//$this->eventDispatcher->dispatch($afterEvent, 'user.afterlogin');*/

			} catch (Exception $e) {
			if ($this->userSession->isLoggedIn()) {
				$a = \OC_Util::getDefaultPageUrl();
				return new RedirectResponse($a);