0
votes

I want to connect to our own oauth2 server, so I wrote an oauth2 login extension, there is the code when I get account information from oauth2 server.

$user = User::newFromName($username);
$user->setEmail($email);
$user->load();

if (!($user instanceof User && $user->getId())) {
    $user->addToDatabase();
}

$user->setToken();
$user->setCookies();
$this->getContext()->setUser($user);
$user->saveSettings();

It will create user data if the user does not exist, but sometimes login will fail if you are not logout by click logout button, and I totally have no clue to solve this problem.

I found MediaWiki has login API, but it required a password and seems not has user auto-creating feature, any reference to accomplish it?

1
Note that setting the email before loading the user does not do anything useful.Tgr
But I indeed login, just logout soon if not doing anything, but it's not about the server session timeout, I am trying to figure outChan

1 Answers

0
votes

In MediaWiki 1.27+ login should be done by writing a PrimaryAuthenticationProvider (before 1.27 there was no non-hacky way to do it for non-password-based logins). See the inline documentation in that class, or this patch which provides similar functionality for OAuth1.