Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow importing user's real name #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ $wgOAuth2Client['configuration']['username'] = 'username'; // JSON path to usern
$wgOAuth2Client['configuration']['email'] = 'email'; // JSON path to email
```

The user's real name will be set to the username by default.
Depending on what you get from your backend, you may also want to configure:
```
$wgOAuth2Client['configuration']['real_name'] = 'realname'; // JSON path to real name
```
or:
```
$wgOAuth2Client['configuration']['first_name'] = 'first_name'; // JSON path to first name
$wgOAuth2Client['configuration']['last_name'] = 'last_name'; // JSON path to last name
```

The **Redirect URI** for your wiki should be:

```
Expand Down
9 changes: 8 additions & 1 deletion SpecialOAuth2Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,14 @@ protected function _userHandling( $response ) {
throw new MWException('Could not create user with username:' . $username);
die();
}
$user->setRealName($username);
if (isset($wgOAuth2Client['configuration']['real_name'])) {
$real_name = $response['user'][$wgOAuth2Client['configuration']['real_name']];
} elseif (isset($wgOAuth2Client['configuration']['first_name']) && isset($wgOAuth2Client['configuration']['last_name'])) {
$real_name = $response['user'][$wgOAuth2Client['configuration']['first_name']] . ' ' . $response['user'][$wgOAuth2Client['configuration']['last_name']];
} else {
$real_name = $username;
}
$user->setRealName($real_name);
$user->setEmail($email);
$user->load();
if ( !( $user instanceof User && $user->getId() ) ) {
Expand Down