cosmocode / dokuwiki-plugin-oauth

Generic oAuth1 and oAuth2 plugin for DokuWiki
http://www.dokuwiki.org/plugin:oauth
30 stars 79 forks source link

Temporary workaround for Azure AD OIDC (possibly even for generic OIDC) #108

Closed haneef95 closed 2 years ago

haneef95 commented 2 years ago

Hi,

After some tinkering I've done some minor changes to the code to implement Azure AD Open ID Connect.

Logic: the Keycloak implementation uses OIDC, so, that would be the easiest one to tinker with.

After installing this plugin (version date 2020-06-14)

Required steps

  1. Create/Register an application in Azure AD
  2. Enter the details for the application in the config page image **Note:** You could use different endpoint urls for auth and token as per your needs.
  3. Edit the KeycloakAdapter.php (located in: \lib\plugins\oauth\classes\KeycloakAdapter.php) file: On line 32, replace: $data['user'] = $result['preferred_username']; (As the Microsoft UserInfo endpoint doesn't supply a 'preferred_username' field. with: $data['user'] = $result['name'];

You can now login through Microsoft by clicking on the Login wtih 'Keycloak' button.

Optional steps (To change the logo and name in the login page)

  1. Upload the Microsoft logo to \lib\plugins\oauth\images\microsoft.png. microsoft

  2. Edit the style.less (located in: \lib\plugins\oauth\style.less) file: After line 55, add:

        a.plugin_oauth_Keycloak {
            .plugin_oauth_button(#999);
            background-image: url(images/microsoft.png);
            padding-left: (20px+24px);
        }
    
        a.plugin_oauth_Keycloak::before {
            content: 'Microsoft - ';
        }

    The code should look like this: image

Result should look like this: image (Not ideal to have it saying 'Keycloak' in the end, but, that's the result.

Hope this helps.

Thanks,

splitbrain commented 2 years ago

an azure adpater can be added as separate plugin now

haneef95 commented 2 years ago

An adapter for AzureAD doesn't exist yet, hence, just using the Keycloak adapter like so:

Key | Value -- | -- plugin»oauthkeycloak»keyClient ID |  `` plugin»oauthkeycloak»secretCient Secret |  `` plugin»oauthkeycloak»openidurlOpenID Connect Auto Discovery URL |  https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration (you could replace `common` with your ``, [more options available here](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-protocols-oidc#fetch-the-openid-connect-metadata-document)) plugin»oauthkeycloak»labelLabel to display on the login button |  Microsoft

Hopefully, an AzureAD adapter is released soon with the Microsoft logo, or even a generic OIDC one with the option to have custom logo and label.

splitbrain commented 1 year ago

Please note that there is an Azure plugin for oauth now: https://www.dokuwiki.org/plugin:oauthazure