Extension:OpenID Connect

PluggableAuth Icon.svg This extension requires the PluggableAuth extension to be installed first.
MediaWiki extensions manual
OOjs UI icon advanced.svg
OpenID Connect
Release status: stable
Implementation User identity
Description Extends the PluggableAuth extension to provide authentication using OpenID Connect.
Author(s) Cindy Cicalese (cindy.cicalesetalk)
Latest version 5.3 (2020-04-10)
Compatibility policy master
MediaWiki 1.27+
PHP 5.3+
Database changes Yes
License MIT License
Download
  • $wgOpenIDConnect_Config
  • $wgOpenIDConnect_UseRealNameAsUserName
  • $wgOpenIDConnect_UseEmailNameAsUserName
  • $wgOpenIDConnect_MigrateUsers
  • $wgOpenIDConnect_ForceLogout
Translate the OpenID Connect extension if it is available at translatewiki.net
Check usage and version matrix.
Issues Open tasks · Report a bug

The OpenID Connect extension extends the PluggableAuth extension to provide authentication using OpenID Connect.

Special thanks to jumbojett for the OpenID Connect PHP library used by this extension.

InstallationEdit

  Note: This extension requires PluggableAuth to be installed first. It also requires the OpenID Connect PHP library, which may be installed using composer.

Install DependenciesEdit

Add the line "extensions/OpenIDConnect/composer.json" to the "composer.local.json" file in the root directory of your wiki, e.g.

{
	"extra": {
		"merge-plugin": {
			"include": [
				"extensions/OpenIDConnect/composer.json"
			]
		}
	}
}

Then run composer update in the root directory of your wiki. This will install any dependencies (i.e. the jumbojett OpenID Connect PHP library).

Configuration parametersEdit

Most configuration for OpenID Connect is handled by a file found at /.well-known/openid-provider on the provider's domain. This contains most of the settings that are needed to handle authentication.

Flag Default Description
$wgOpenIDConnect_Config no default value A mandatory array of arrays specifying the OpenID Connect issuers and their configuration. The key of the containing array entry is the URL (e.g. https://accounts.google.com/) of the issuer. The URL is used to find the "well-known" file mentioned above. The contained array has the following keys:
  • clientID (mandatory)
  • clientsecret (mandatory)
  • name (optional label text)
  • icon (optional URL)
  • proxy (optional URL)
  • scope (optional string or array of strings to be passed to the issuer)
  • preferred_username (optional preferred username field from issuer to use)
  • verifyHost (optional boolean to enable/disable host verification; default: true)
  • verifyPeer (optional boolean to enable/disable SSL peer verification; default: true)
  • authparam (optional associative array of authentication parameters to be passed to the issuer)

If multiple issuers are provided, a selection special page will be presented to the user upon login. name and icon are used on that page to display the issuers.

$wgOpenIDConnect_UseRealNameAsUserName false If a new user is being created in the database and no preferred username was provided by the issuer, a value of true for this flag indicates that the user's real name, if provided by the issuer, should be used as the new user's username.
$wgOpenIDConnect_UseEmailNameAsUserName false If a new user is being created in the database, and no preferred username was provided by the issuer, and either no real name was provided by the issuer or $wgOpenIDConnect_UseRealNameAsUserName was undefined or set to false, a value of true for this flag indicates that the name portion of the user's email address, if provided by the issuer, should be used as the new user's username.
$wgOpenIDConnect_MigrateUsersByUserName false If a user already exists in the database with the same user name as the authenticated user and has null values for subject and issuer, use this user, setting the subject and issuer in the database to those of the authenticated user. This is useful when the wiki previously used a different authentication mechanism.
$wgOpenIDConnect_MigrateUsersByEmail false If a user already exists in the database with the same email address as the authenticated user and has null values for subject and issuer, use this user, setting the subject and issuer in the database to those of the authenticated user. This is useful when the wiki previously used a different authentication mechanism.
$wgOpenIDConnect_ForceLogout false Upon logout, request authentication passing attribute prompt with a value of login (not fully supported by all OpenID Connect servers yet).

When configuring the identity provider, it will ask for a redirect URL or callback URL. Use the full URL to the Special:PluggableAuthLogin page for that value.

A simple example of the $wgOpenIDConnect_Config configuration for a single issuer is as follows:

$wgOpenIDConnect_Config['https://id.mycompany_abc.com/connect/'] = [
    'clientID' => '.....',
    'clientsecret' => '.....'
];

An example of the $wgOpenIDConnect_Config configuration for multiple issuers is as follows:

$wgOpenIDConnect_Config['https://id.mycompany_abc.com/connect/'] = [
    'clientID' => '.....',
    'clientsecret' => '.....',
    'name' => "My Company's Connect Server",
    'icon' => 'http://www.mycompany_abc.com/images/logo.png'
];

$wgOpenIDConnect_Config['https://id.partnercompany_def.com/connect/'] = [
    'clientID' => '.....',
    'clientsecret' => '.....',
    'name' => "Partner Company's Connect Server",
    'icon' => 'http://www.partnercompany_def.com/images/logo.png'
];


Example: Google as an IssuerEdit

  1. Using the Google Developer Console create a project.
  2. Click on the project, click on the hamburger menu (three horizontal lines in the top left), and click on APIs & Services -> Credentials on the menu.
  3. Click the Create credentials -> OAuth client ID button and select Web application. Fill in the consent screen information and save.
  4. Fill in the full URL of the Special:PluggableAuthLogin page of your wiki in Authorized redirect URIs.
  5. Click Create Client ID.
  6. Note the Client ID and Client Secret that are assigned.

The Google issuer is now configured. Add the corresponding configuration to your LocalSettings.php file, filling in the clientID and clientsecret fields with the values assigned above.

$wgOpenIDConnect_Config['https://accounts.google.com'] = [
    'clientID' => '.....',
    'clientsecret' => '.....',
    'scope' => [ 'openid', 'profile', 'email' ]
];

You may also assign values for name, icon, proxy and authparam.

Example: Using it against Azure ADFSEdit

Three parameters are required to use this extension to authenticate against Azure ADFS: a tenant id, a client id, and a secret.

$wgOpenIDConnect_Config['https://sts.windows.net/ReplaceWithYourTenantID/'] = [
        'clientID' => 'ReplaceWithYourClientID',
        'clientsecret' => 'ReplaceWithYourSecret'
    ];

Example: Using it against KeycloakEdit

Assumptions:

  • Your Keycloak realm name is acme
  • Your Keycloak URL and Port is https://keycloak.local:8080
  • Your Keycloak Client ID is set to mediawiki
  • Your auto-genertated client secret is 12345
$wgOpenIDConnect_Config['https://keycloak.local:8080/auth/realms/acme/'] = [
        'clientID' => 'mediawiki',
        'clientsecret' => '12345'
    ];

Troubleshooting:

  • If you´re running into trouble, like "The provider {$param} could not be fetched. Make sure your provider has a well known configuration available.", your URI is wrong. You can test the corretness by calling https://keycloak.local:8080/auth/realms/acme/.well-known/openid-configuration in your browser. If you get back a long JSON, the path is correct.
  • Make sure the redirect uri provided by this OIDC plugin is set valid for your keycloak-server under acme -> Clients -> mediawiki -> Settings -> valid redirect uris . For testing purposes you can add a wildcard "*".

Example: Using it with OktaEdit

  Note: As of the date this example was written, a bug exists in the OpenID Connect PHP library which causes stricter OIDC providers like Okta to reject certain requests. This should be resolved in the future when the library is updated to incorporate the change. The solution is to add a single line of code to $MEDIAWIKI_ROOT/extensions/OpenIDConnect/vendor/jumbojett/openid-connect-php/src/OpenIDConnectClient.php as follows: right below: unset($token_params['client_secret']); simply add: unset($token_params['client_id']); # see https://github.com/jumbojett/OpenID-Connect-PHP/pull/208/commits/dd44c1ca7e45d35dcd8f32ea503b545149bc6562

To authenticate your users against Okta, you must first create a new OIDC app in your Okta org and assign it to the relevant users/groups, etc.

Okta OIDC app settingsEdit

Allowed grant types: (all)
Login redirect URIs: the full URL to Special:PluggableAuthLogin, e.g. https://www.example.com/wiki/index.php/Special:PluggableAuthLogin
Login flow: "Redirect to app to initiate login (OIDC compliant)"
Initiate login URI: the full URL to Special:UserLogin, e.g. https://www.example.com/wiki/index.php/Special:UserLogin

Extension settingsEdit

You must specify the openid, profile, and email scopes to communicate with Okta. If you omit the appropriate scopes, Okta will gladly authenticate your users but will not return any useful claims.

$wgOpenIDConnect_Config['https://your-okta-org.okta.com'] = [
        'clientID' => '(paste the client ID Okta assigned your new app here)',
        'clientsecret' => '(paste the client secret Okta assigned your new app here)',
        'scope' => [ 'openid', 'profile', 'email' ]
    ];

Auto-creating usersEdit

If you want to take advantage of MediaWiki's user auto-creation (e.g. $wgGroupPermissions['*']['autocreateaccount'] = true;), be aware that Okta's preferred_username claims take the format of an email address.

If you do not want your users to have an @ character in their usernames (this is forbidden by MediaWiki by default), you will need to specify an alternative claim to use via the 'preferred_username' key in your $wgOpenIDConnect_Config.

Allowing @ in usernames may break your wiki's Interwiki compatibility (if you rely on that). To allow the use of the @ character, just set $wgInvalidUsernameCharacters = ' '; and $wgUserrightsInterwikiDelimiter = '#'; in LocalSettings.php.

Release NotesEdit

Version 5.2
  • Fixed bug with migrated initial lowercase usernames (T249630)
Version 5.2
  • Added optional configuration options for disabling the verification of hostnames and certificates, for use in development environments with self-issued certificates
Version 5.1
  • Added generation of full redirect URL so OpenID Connect PHP library doesn't have to guess, which occasionally it didn't have enough information to do accurately
Version 5.0
  • Moved subject and issuer columns from user table to openid_connect table (requires database update)
  • Added support for Postgres
Version 4.1
  • Added namespace for library class
Version 4.0
  • Added optional error message to authenticate()
  • Bumped version number to synchronize with PluggableAuth and SimpleSAMLphp extensions
Version 2.3
  • Fixed whitelist implementation
  • Changes migration flags to allow migration by email address in addition to migration by user name
Version 2.2
  • Fixes related to PluggableAuth MediaWIki 1.27 upgrade
  • Array coding conventions
Version 2.1
  • Update to MediaWiki 1.27 session management
  • Added default values for configuration variables to extension.json
Version 2.0
  • Updated extension registration
  • Changed configuration variables to use "wg" prefix
  • Added composer.json to get OpenID Connect library using composer
Version 1.2
  • Added ability to specify auth params and added support for table prefixes
Version 1.1
  • Added support for Google
Version 1.0
  • Initial version

Known BugsEdit

  • Wikis that use URLs of the form http://example.org/w/index.php?title=Page_title (i.e. having the page title provided as a query parameter) will not be redirected correctly to complete the authentication flow. Instead, URLs must be of the form http://example.org/w/index.php/Page_title, which can be accomplished by using short URLs or by setting $wgArticlePath appropriately.
  • This extension may not work correctly with $wgMainCacheType = CACHE_ACCEL (see T147161).
  • This extension does not work on non-standard ports unless you manually update the underlying Openid connect client, see: https://github.com/jumbojett/OpenID-Connect-PHP/issues/58. Issue also applies when to other webserver than IIS.

See alsoEdit