I try to post simple example how to use OpenID with AuthKit 0.4.3 and Pylons 0.9.7. by adapting example from AuthKit. So I just create new Pylons app named “topenid” and modify it as follow:
These lines below are added to development.ini
authkit.setup.enable = true authkit.setup.method = openid, cookie authkit.openid.store.type = file authkit.openid.store.config = authkit.openid.charset = UTF-8 authkit.openid.path.signedin = /auth/signin authkit.cookie.signoutpath = /auth/signout authkit.openid.store.baseurl = http://localhost:5000 authkit.cookie.secret = somesecret
... import authkit.authenticate # this line is added ... app = PylonsApp() app = authkit.authenticate.middleware(app, app_conf) # this line is added ...
import logging from pylons import request, response, session, tmpl_context as c from pylons.controllers.util import abort, redirect_to from authkit.permissions import RemoteUser from authkit.authorize.pylons_adaptors import authorize from topenid.lib.base import BaseController, render log = logging.getLogger(__name__) class AuthController(BaseController): def index(self): return 'Hello World' @authorize(RemoteUser()) def test(self): return 'test' def signout(self): return 'signout' def signin(self): return 'signed in'
These are all modifications. I can access http://localhost:5000/auth/index as expect and http://localhost:5000/auth/test is redirected to an OpenID signin page. And I can sign out by visiting http://localhost:5000/auth/signout.
This example seems to work well but I need something more complex for example every user doesn’t have the same role. So I may post another more complex example soon.