innocode-digital/wp-github-oauth

This package is abandoned and no longer maintained. No replacement package was suggested.

Allows Single Sign On into WordPress through Github OAuth app with restriction by organization and team.

Installs: 5 965

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Type:wordpress-muplugin

1.2.3 2019-12-05 16:25 UTC

This package is auto-updated.

Last update: 2023-06-06 04:15:34 UTC


README

Description

Allows Single Sign On into WordPress through Github OAuth app with restriction by organization and team.

Install

  • Preferable way is to use Composer:

    composer require innocode-digital/wp-github-oauth
    

    By default it will be installed as Must Use Plugin. But it's possible to control with extra.installer-paths in composer.json.

  • Alternate way is to clone this repo to wp-content/mu-plugins/ or wp-content/plugins/:

    cd wp-content/plugins/
    git clone git@github.com:innocode-digital/wp-github-oauth.git
    cd wp-github-oauth/
    composer install
    

If plugin was installed as regular plugin then activate Github OAuth from Plugins page or WP-CLI: wp plugin activate wp-github-oauth.

Usage

Add required constants (usually to wp-config.php):

define( 'GITHUB_OAUTH_CLIENT_ID', '' );
define( 'GITHUB_OAUTH_CLIENT_SECRET', '' );
define( 'GITHUB_OAUTH_ORGANIZATION', 123456 ); // Organization ID
define( 'GITHUB_OAUTH_TEAMS2ROLES', [
    'super_admin'   => [
        123456, 234567,
    ], // Applicable to Multisite, will be the same as 'administrator' for single sites
    'administrator' => [
        345678,
    ],
    'editor'        => [
        456789, 567890, 654321,
    ],
] );

IMPORTANT: keys in GITHUB_OAUTH_TEAMS2ROLES are equal to roles (see Roles and Capabilities) and should be in descendant order by capability since first match will be used in case when user is in different teams.

Documentation

By default auth URL is using github as an endpoint but it's possible to change with constant:

define( 'INNOCODE_GITHUB_OAUTH_ENDPOINT', '' );

It's possible to change Github OAuth scope:

add_filter( 'innocode_github_oauth_scope', function ( array $scope ) {
    return $scope; // Default is array containing 'user:email' and 'read:org'.
} );

It's possible to change place where endpoint should be added:

add_filter( 'innocode_github_oauth_endpoint_mask', function ( $mask, $endpoint ) {
    return $mask; // Default is EP_ROOT constant.
}, 10, 2 );

To check if user used Github OAuth:

innocode_github_oauth()->is_identified( $user_id );