How to register a custom identify provider?

2 views
Skip to first unread message

Barry Hart

unread,
Jun 19, 2007, 3:33:13 PM6/19/07
to TurboGears
I have written a custom identity provider (similar to the existing
SqlAlchemyIdentityProvider and SqlObjectIdentityProvider classes). In
TG 1.0.1, how do I ask TG to use my provider instead of these?

>From my initial reading of the code, the create_default_provider()
function in turbogears.identity requires that the class be listed in
this section of entry_points.txt of the TurboGears egg:

[turbogears.identity.provider]
sqlobject =
turbogears.identity.soprovider:SqlObjectIdentityProvider
sqlalchemy=
turbogears.identity.saprovider:SqlAlchemyIdentityProvider

But I don't want to patch the TurboGears files to do this.

What's the right way to do this?

Barry

Florent Aide

unread,
Jun 19, 2007, 4:28:32 PM6/19/07
to turbo...@googlegroups.com
Hi Barry,

In branch 1.0 you can just specify your provider "name" directly in
the <proj>/config/app.cfg in the "identity.provider" variable.

As long as your provider is registered with the
"turbogears.identity.provider" entry point it will be found by the
identity loader.

exemple:

your provider has this kind of thing in setup.py:

============================

setup(
name="SuperIDProvider",
version="0.1",
description="the Super ID Provider",
author="You",
author_email="y...@you.com",
url="http://womewhere.org",
download_url="",
license="MIT",
zip_safe=False,
entry_points="""
[turbogears.identity.provider]
mysuperprovider = superprovider.plugin:SuperProvider
""",
test_suite = 'nose.collector',
)

============================

If you install such an egg somewhere in you python path, you just have
to specify in your app.cfg:

identity.provider=mysuperprovider

to have it loaded.

Some explanations:
==============

[turbogears.identity.provider]
mysuperprovider = superprovider.plugin:SuperProvider

Specifies to setuptools that the name "mysuperprovider" is registered
for the entry point turbogears.identity.provider and points to the
class SuperProvider that can be found in the superprovider.plugin
module.

This means your plugin once installed in the python path or in a
registered plugin dir (more in this subject on demand :)) will be
found by any program that executes a:

pkg_resources.iter_entry_points("turbogears.identity.provider",
'mysuperprovider')

Incidentally in branch 1.0 you can now directly specify the name of a
class with a full python name like this:

identity.provider=some.python.module.SuperProvider

but this is less elegant and should not be the preferred way ;-)

Hope it help, my brain is melting-down from overwork at the moment so
excuse my quick and less than complete answer,

Cheers,
Florent.

Barry Hart

unread,
Jun 19, 2007, 4:36:57 PM6/19/07
to TurboGears
Thanks, this is very helpful! I had mistakenly assumed that only
TurboGears itself could list an entry point in
turbogears.identity.provider.

Barry

Timothy Freund

unread,
Jun 20, 2007, 12:13:18 AM6/20/07
to turbo...@googlegroups.com
I just wrote an article about this very topic a few days ago -- I guess
I am a little too slow in getting around to announcing it... to anyone
else who is interested in customizing an identity provider, you might
check this out:

http://achievewith.us/public/articles/2007/06/13/change-your-identity-in-turbogears-with-entry-points

Comments and suggestions are welcome,


Tim

--
Timothy Freund
http://digital-achievement.com
http://edodyssey.com

Reply all
Reply to author
Forward
0 new messages