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

New Plugin: Provide HTTP_AUTH Authentication for Piwik - Release in Marketplace #514

Closed
robocoder opened this issue Jan 20, 2009 · 40 comments
Labels
Critical Indicates the severity of an issue is very critical and the issue has a very high priority. Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Milestone

Comments

@robocoder
Copy link
Contributor

Plugin that forwards the current HTTP_AUTH’ed user to Piwik

```

  • What is HttpAuthLogin plugin ?
    ```

It’s a plug-in that authentifies users based on HTTP_AUTH. HTTP_AUTH is a mechanism provided by the webserver itself (I tested this with Apache). The webserver prompts the user for a login and password, matches it to a database (or a file, you decide), and if the authentication is successful, it lets you access the current logged-in user from PHP.

```

  • What use cases is HttpAuthLogin useful ?
    ```

If you have several web services running on the same machine, you can achieve Single Sign-On. For instance, if you run Piwik, a bug tracker, and a WebDAV disk space on the same web server, you could log-in once on the bug tracker, and be automagically logged-in on Piwik.

HTTP_AUTH is extremely widely supported. Even command-line tools like cURL or wget support it. If for some reason you’d like to write a script that fetches stuff out of Piwik, but you’d like it to be authentified, it’d be a lot easier to do with HttpAuthPlugIn.

Contributed by Romain Goyet.

Requires review per [wiki:CodingStandard].

Keywords: third-party-plugin

@robocoder
Copy link
Contributor Author

New in version 0.2:

  • Should conform to coding standard
  • Compatible with 0.2.37
  • Logout link

Extract into plugins folder and activate via Settings | Plugins menu.

@robocoder
Copy link
Contributor Author

Note: The AuthName from your .htaccess file is not passed to PHP. If you need to change the realm name, "Piwik" is hard-coded in plugins/HttpAuthLogin/Controller.php.

@robocoder
Copy link
Contributor Author

Note: token_auth authentication is not available with this plugin

@robocoder
Copy link
Contributor Author

A sample .htaccess file can be found in: http://forum.piwik.org/index.php?showtopic=4431

@robocoder
Copy link
Contributor Author

But I tested the updated plugin on the 1.0 branch, and it worked fine there.

@anonymous-matomo-user
Copy link

I've just had the time to try the HttpAuthLogin plugin with version 1.0. I logged in as administrator, enabled the plugin and when I reload the page it throws me back to the Piwik login screen. I previously authenticated with the webserver using a different username then administrator, but this username doesn't exist in Piwik. I tried clearing my HTTP auth information and then loading piwik again. I logged in to Apache again but this time Piwik falls into an infinite redirect loop.

Can you give a brief description on how exactly to use this plugin? I use LDAP for authentication in Apache and usernames are user@domain.com. I tried manually creating a user account in Piwik to match my email address, but it wouldn't allow me to use the @ character in the username. Thanks, -Tim

@robocoder
Copy link
Contributor Author

Tim: this plugin requires that you set up an .htaccess file and password file. In your case, shouldn't you be using #734?

@anonymous-matomo-user
Copy link

Replying to vipsoft:

Tim: this plugin requires that you set up an .htaccess file and password file. In your case, shouldn't you be using #734?

For one, I'd prefer to stick with multi-layers of security: Password protect all of Piwik with Apache HTTP authentication (over SSL of course) while still having Piwik user accounts handle access control to the analytics data for each site. But I was hoping this plugin would pass along the credentials from HTTP authentication to Piwik. Isn't this what was intended?

As for using the plugin for LDAP authentication, it seemed more complicated to setup and hasn't been updated in 13 months (maybe that just means it's working as expected). Since I already had Apache HTTP authentication setup using LDAP, I thought it would be easier to use the HTTP_AUTH plugin.

-Tim

@anonymous-matomo-user
Copy link

That plugins works fairly well except one big things : the .htaccess breaks the API access with token_auth.

How could it be made so it doesn't break the token_auth ?

@anonymous-matomo-user
Copy link

mmm, it seems that, as soon as you enable this plugin (even without any .htaccess file), the token_auth access is broken. (SitesManager.getSitesWithAdminAccess always returns an empty value)

@mattab
Copy link
Member

mattab commented Nov 16, 2010

See #1766 for a patch to a possible bug in this plugin.

@robocoder
Copy link
Contributor Author

Changelog:

@anonymous-matomo-user
Copy link

Like Tim I also had the redirect loop problem.
I looked into the sources and just added another if else block to make it work on my apache server with mod_sspi authentication.

Auth.php:
...

if(isset($_SERVER['PHP_AUTH_USER']))
{
    $httpLogin = $_SERVER['PHP_AUTH_USER'];
}
else if(isset($_SERVER['HTTP_AUTH_USER']))
{
    $httpLogin = $_SERVER['HTTP_AUTH_USER'];
}
else if(isset($_SERVER['REMOTE_USER']))
{
    $httpLogin = $_SERVER['REMOTE_USER'];
}

...

@robocoder
Copy link
Contributor Author

Changelog:

  • 0.3.3 - added domruf's patch for mod_sspi

@robocoder
Copy link
Contributor Author

Attachment: v0.3.4
HttpAuthLogin.zip

@robocoder
Copy link
Contributor Author

Changelog for 0.3.4

  • use $_ENV instead of $_SERVER in case variables_order excludes 'E'
  • added AUTH_USER and REDIRECT_REMOVE_USER
  • removed HTTP_AUTH_USER

@anonymous-matomo-user
Copy link

This should get listed in the list of plugins b/c this is very valuable for any enterprise organization.

@anonymous-matomo-user
Copy link

Maybe someone is running into similar problems: At first I couldn't get it to work with a clean PIWIK 1.7.1 install, because I always ran into a redirect loop problem, when I activated the plugin.

After a lot of trial and error I found out that I have to deactivate the standard authentication and after that insert:

PluginsInstalled[] = "HttpAuthLogin"
Plugins[] = "HttpAuthLogin"

in the config/config.ini.php manually. It works now!

@anonymous-matomo-user
Copy link

I've found that not setting token auth upon authentication breaks some functionality as the superuser. So I wrote an updated version of Auth.php that sets the token_auth (instead of NULL) on successful authentication, and also replaces the Zend_Registry calls with the appropriate calls Piwik_config::getInstance() and Piwik_FetchOne.

@anonymous-matomo-user
Copy link

    public function authenticate()
    {
        $rootLogin = Piwik_config::getInstance()->superuser['login'];
        $rootPassword = Piwik_Config::getInstance()->superuser['password'];

        $httpLogin = null;
        if(isset($_SERVER['PHP_AUTH_USER']))
        {
            $httpLogin = $_SERVER['PHP_AUTH_USER'];
        }
        else if(isset($_ENV['AUTH_USER']))
        {
            $httpLogin = $_ENV['AUTH_USER'];
        }
        else if(isset($_ENV['REMOTE_USER']))
        {
            $httpLogin = $_ENV['REMOTE_USER'];
        }
        else if(isset($_ENV['REDIRECT_REMOTE_USER']))
        {
            $httpLogin = $_ENV['REDIRECT_REMOTE_USER'];
        }

        if(isset($httpLogin))
        {
            if($httpLogin === $rootLogin)
            {
                $rootToken = Piwik_UsersManager_API::getInstance()->getTokenAuth($rootLogin, $rootPassword);
                return new Piwik_Auth_Result(Piwik_Auth_Result::SUCCESS_SUPERUSER_AUTH_CODE, $httpLogin, $rootToken );
            }

            $auth = Piwik_FetchRow(
                'SELECT login, token_auth FROM '.Piwik_Common::prefixTable('user').' WHERE login = ?',
                array($httpLogin)
            );

            if(isset($auth['login'])
                && $auth['login'] === $httpLogin)
            {
                return new Piwik_Auth_Result(Piwik_Auth_Result::SUCCESS, $httpLogin, $auth['token_auth'] );
            }

            return new Piwik_Auth_Result( Piwik_Auth_Result::FAILURE, $httpLogin, NULL );
        }

        return parent::authenticate();
    }

@anonymous-matomo-user
Copy link

+1 following

@anonymous-matomo-user
Copy link

Hey. I added a rewrite for piwik 2.0. It seams to work for me but it may need a review.

@anonymous-matomo-user
Copy link

i keep getting

Cannot access parent:: when current class scope has no parent

in

piwik/plugins/HttpAuthLogin2/Auth.php line 84

@anonymous-matomo-user
Copy link

thx, I fixed this and another critical bug in db query

@anonymous-matomo-user
Copy link

@nougad thanks for your work on this. I was wondering, though, why did you choose to change Auth to implementing Core Auth instead of extending the Login plugin like the previous version? It seems like a lot of additional code for which you could simply fall back on the Login plugin instead.

@anonymous-matomo-user
Copy link

@drammons Do you mean I should extend the exiting Auth class instead of implementing the Auth interface? I had no real reason and your suggestion makes sense. I will change it that way. Thx

@anonymous-matomo-user
Copy link

Yes! That is exactly what I meant. Good work!

@anonymous-matomo-user
Copy link

I had to add:

use Piwik\Common;

...to Auth.php to get this working.

@anonymous-matomo-user
Copy link

Attachment: Rewrite for piwik 2.0
HttpAuthLogin2.tgz

@anonymous-matomo-user
Copy link

@jarkko fixed - thx

@anonymous-matomo-user
Copy link

Heads up as ticket:4564 rolls out, adding support for multiple super users.

@anonymous-matomo-user
Copy link

Piwik 2.0.3 still tells me this plugin doesn't work Piwik. What am I doing wrong?

@anonymous-matomo-user
Copy link

@digantk - sure you used the HttpAuthLogin2.tgz file? Not the HttpAuthLogin.tgz one

@anonymous-matomo-user
Copy link

Replying to nougad:

@digantk - sure you used the HttpAuthLogin2.tgz file? Not the HttpAuthLogin.tgz one

I'm very sure. The directory is HttpAuthLogin2 and has the HttpAuthLogin2.php file in it and the error message in the plugin manager says HttpAuthLogin2. :-/

@mattab
Copy link
Member

mattab commented Feb 6, 2014

Along with the Piwik 2.0 release and new design for Piwik, we have also launched the official Plugins Marketplace to let any developer share their work to the thousands of Piwik users worldwide.

Maybe you'd like to publish your plugin there?

In any case, keep up the good work and we hope you enjoy Piwik 2!

--> See also example of the Ldap plugin #734 published on the Marketplace at: http://plugins.piwik.org/LoginLdap

@anonymous-matomo-user
Copy link

Please add it to the marketplace. Without this plugin (and soon), I'll have lose the argument against Google Analytics and I'll have to drop the use of Piwik.

@mattab
Copy link
Member

mattab commented Feb 9, 2014

Thanks for the suggestion. Indeed I think it makes sense that the Piwik team officially supports this important plugin. We will release it on the Marketplace soon, and will then officially support it going forward.
stay tuned!

@mattab
Copy link
Member

mattab commented Feb 10, 2014

In 5d49e72: Refs #514 Adding HttpAuth plugin as submodule, now hosted at: https://github.com/piwik/plugin-LoginHttpAuth

@mattab
Copy link
Member

mattab commented Feb 10, 2014

In 8d156bd: Refactor core Login to allow for clean LoginHttpAuth logic refs #514

@mattab
Copy link
Member

mattab commented Feb 10, 2014

Thanks for your patience! the HttpAuth login is now published on the Marketplace at: http://plugins.piwik.org/LoginHttpAuth

please test it and report any issue in the Github issue tracker: https://github.com/piwik/plugin-LoginHttpAuth/issues

Cheers!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Critical Indicates the severity of an issue is very critical and the issue has a very high priority. Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Projects
None yet
Development

No branches or pull requests

3 participants