Tropical Software Observations

02 December 2008

Posted by Irregular Zero

at 11:06 AM



Clickpass plugin for Grails, Part 1

Clickpass works by handling the OpenID authentication and sending it back to the site. This means that any Grails app using this plugin must also install the OpenID plugin. Also the site will need to be registered with Clickpass and some settings need to be set online. When the authenticated details are sent back, the user is logged in and sent to the welcome page, sent to a form for details to complete registration or asked to login to attach the OpenID to an existing user account.

  • grails create-plugin clickpass.
  • Add ClickpassController.groovy to grails-app/controller.
  • Add User.groovy to grails-app/domain. This is a dummy file required for the plugin to be packaged.
  • Add ClickpassTagLib.groovy to grails-app/taglib.
  • Add _clickpass.gsp to grails-app/views.
  • Add welcome.gsp to grails-app/views/clickpass.

class ClickpassController {
def openidService

def index = { response.sendError(404) }

def welcome = {
def user = null

if (openidService.isLoggedIn(session)) {
user = User.findByOpenid(openidService.getIdentifier(session))
if (user == null) {
def urlString = "

def merge = {
def user = User.findByUsernameAndPassword(params.user_id, params.password)
def urlredirect = +

if (user == null) {

user.openid = openidService.getIdentifier(session)

if ( {
else {

def register = {
def user = new User()
user.username = params.nickname =
user.openid = openidService.getIdentifier(session)
user.password = ''

if ( {
flash.message = "Thank you for signing up."
redirect(controller:'clickpass', action:'welcome')
else {
flash.message = "There is a problem signing up."
redirect(controller:'clickpass', action:'index')
  • index: Nothing for the index to do so set up a 404.
  • welcome: When a user is authenticated by OpenID, a search is made to see whether that OpenID is in the database, if not then redirect to the registration page. The urlString is obtained from Clickpass so this needs to be changed for each site
  • merge: A user, authenticated by OpenID, who wants to attach the ID to his account.
  • register: Create a new user account with the OpenID and save it.

Nothing in it except for the class declaration.

class ClickpassTagLib {
static namespace = "clickpass"

def bar = { attrs, body ->
try {
out << render(template:"/clickpass", contextPath:"${pluginContextPath}")
catch(Exception e) {
  • The namespace allows one to use it, i.e <clickpass:foobar/>, in the code instead of the generic <g:foobar/>
  • For usage in an app, all that is required is <clickpass:bar/> to be inserted into the html.
  • The / in the template name is necessary to revert the path to the project base, otherwise it would go looking in the main app views folder.
  • The contextPath:"${pluginContextPath}" is not mentioned in the documention but after setting the path to the base, this sets it to the correct plugin views folder.

The html for this is generated by Clickpass, after registering your site, you can just copy and paste. This creates the Clickpass login bar.

<link rel="openid.server" href="" />
<link rel="openid.delegate" href="" />
<openid:identifier />
  • This is a simple welcome page after the user successfully logs in and his account is verified.
  • One can replace it with their own or redirect from this page.
  • The OpenID is displayed as well as a logout link.

  • grails package-plugin to get it all into a zip file.
  • grails install-plugin /path/to/plugin/ to install it into an app.