wiki:SharedCookieAuthPlugin

Version 12 (modified by Ryan J Ollos, 8 years ago) (diff)

Use project-relative URLs.

Share Trac cookies between projects in the same environment

Notice: This plugin does not necessarily meet coding standards or functions correctly in all use cases.

Description

This plugin allows cookies to be shared between Trac instances in the same environment, ie directory. The plugin monkey-patches trac.web.auth.LoginModule so that cookies get set at / instead of req.base_path, see following note. The incoming request is then passed by the authenticate method of the IAuthenticator interface to projects that peer the project of interest to see if the user is authenticated there. This enables single-sign on for Trac projects in the same directory.

Note 1: As per request in t#8486 a new configuration option has been introduced to Trac with changeset t:[9226] that accomplished this:

[trac]
auth_cookie_path = /var/www/trac

So this has been made a part of Trac, and a simplified plugin version (not yet available) should work for Trac version >= 0.12 without that monkey-patching.

Note 2: Before recent maintainer take-over, this plugin inspired a native Single-Sign-On functionality in AccountManagerPlugin, that is stable, available since acct_mgr-0.4 and even solves some of the shortcomings of this plugin. Most importantly login/logout works from any Trac environment sharing identical cookie path settings.

Bugs/Feature Requests

Existing bugs and feature requests for SharedCookieAuthPlugin are here.

If you have any issues, create a new ticket.

defect

2 / 2

enhancement

1 / 1

task

1 / 1

Download

Download the zipped source from here.

Source

You can check out SharedCookieAuthPlugin from here using Subversion, or browse the source with Trac.

Installation

Install the plugin on multiple Trac instances in the same directory that use cookie-based auth. Then logging in to one, should mirror login to all of them.

Configuration

To make this work you will need to select one of the project to be the master authenticator, the other (slave) projects should be configured to pass the authenticate request onto the master project. This is to avoid one project to kill the auth_cookie if the login was made in another project. Unfortunately this means that login and logout can only be made in the master project.

So for the slave projects you'll need to disable the normal way of authentication while enabling the sharedcookieauth:

[components]
sharedcookieauth.* = enabled
trac.web.auth.LoginModule = disabled

[trac]
auth_cookie_path = /

And for the master project:

[components]
sharedcookieauth.* = enabled
trac.web.auth.LoginModule = enabled

[trac]
auth_cookie_path = /

The sharedcookieauth should not need to be enabled in the master project, but it shouldn't harm either. Also be aware that the server name used must match or the browser will not share the auth_cookie between the projects.

Recent Changes

15486 by rjollos on 2016-04-18 08:56:13
0.1.6dev: Refactor code and update documentation
15122 by rjollos on 2015-12-14 06:13:30
0.1.5: Tag sharedcookieauth-0.1.5

Bump trunk version to 0.1.6dev.

15091 by rjollos on 2015-12-01 18:21:00
0.1.5dev: Rename method added in [15075]

  • Document internal methods.

Refs #12592

(more)

Author/Contributors

Originally developed at The Open Planning Project

Author: k0s
Maintainer: agitronic
Contributors: