OUR BLOG

Thoughts on development, design and the world we live in.



Typus Custom Authentication

By lorien in Uncategorized. Posted on February 18th

We really like Typus at Blazing Cloud, and we end up using it in most of our Ruby on Rails projects. It provides good enough UI for a lot of our data entry needs, and is very quick to set-up. We also use Devise for authentication, and frequently end up with both in the same project. In many cases it is ideal for Typus to have it’s own auth system, as often the end users of the system are not also administrators of the system. However, there are some cases where the end users are also users of the Typus interface, and in that case it is convenient to have only one set of credentials to log in to both parts of the system.

We found a fairly simple way to plug a custom auth component into Typus which I will demonstrate here using Devise authentication as an example. To provide a custom mechanism for authentication all you need to do is include a module inside a module called Authentication inside a module called Typus, and then set the config.authentication property in the Typus initializer equal to the symbol version of your module’s name. For example, here is our custom module which we called Devise:

The key here is to include the authenticate method, which gets called by Typus when auth is turned on. Then in the Typus initializer you need to configure Typus to use your module:

This just refers to the Devise module by the symbol version of its name. Now just require your module in your project, and that’s it! Now when you visit your Typus admin page you will be required to log in using Devise authentication.

Note the line in the Devise module that creates the @admin_user property:

The @admin_user variable must be set to a valid user if authentication is turned on in Typus or you will get errors. The FakeUser user is used internally by Typus as a placeholder model, and has all of the required attributes so we use it here. The Typus user model is only used if you have authentication turned on, and isn’t required for any of the basic functionality. However, you can also set @admin_user to a real user model such as your Devise user model, if you make sure it has the required Typus attributes. For example, if you want turn on user specific localization in Typus you can set @admin_user to a user model that has the “locale” property set on it.

By lorien | Posted in Uncategorized | Comments (4)

3 Comments

  1. Posted February 26, 2011 at 3:08 pm | Permalink

    Thanks for writing about Typus.

    I’ve been working on adding devise support to typus. Branch is available at https://github.com/fesplugas/typus/commits/wip/devise.

  2. Matthias
    Posted March 31, 2011 at 7:26 pm | Permalink

    Hi!
    Very nice! But I followed your instructions and I could not create my own module for my authentication, like you did it with :devise.

    If I do that, I get always:
    uninitialized constant Typus::Authentication::MyAuth

    After that I tried to override the :session module and here I always get:
    undefined local variable or method `crypted_password’
    if I update an User.

    Do you have an idea, what could be my problem?

  3. Lorien
    Posted April 4, 2011 at 10:14 am | Permalink

    Hi Matthias,

    Thanks for your comment. You do need to require your helper module. I required mine in my environment.rb file like so:

    require File.expand_path(‘../../app/helpers/typus/authentication/devise’, __FILE__)

    does that help?

One Trackback

  1. [...] This post was mentioned on Twitter by Sarah Allen, Blazing Cloud, Inc.. Blazing Cloud, Inc. said: Typus Custom Authentication with Devise (Rails) >> http://bit.ly/ekOxA0 [...]

Post a Comment

Your email is never shared. Required fields are marked *

*
*