In our current project we were asked to implement twitter signup/login functionality using Oauth . We did some research and decided to use the Oauth Plugin and here are the steps we followed :

Step 1 : Install the Oauth plugin

We opened BuildConfig.groovy and added the following dependency inside plugins section :

Step 2 : Sign up as twitter developer and create a new application

You can sign up for twitter developer account from the this link. After successful sign in/sign up all you need to do is to create a new application. You can create a new application from your dashboard.

  • Click on “Create New Application” button
  • Fill out the form
  • On this page enter the Website URL. Let’s assume your website is and if you are running your grails application on your local machine then you have to edit your host file and map to your website URL using the following :
  • You can check

    this link

    to find out how to modify your host file.

  • Till now you are done mapping your website to localhost but the callback URL in twitter app is still not done. If your grails application is running on root context then you need to add the following in callback URL :

    But if you are app is not running in the root context then you need to add the app name in the callback URL and the value will look like this

  • Save these changes and now let’s get back to your Grails application

Step 3 : Add Config values in Config.groovy


Step 4 : Add twitter link in your sign up page

This is the easy part. You just need to add a new tag to your sign up page. It is mentioned in the official docs that you need to add the following tag in your GSP :

Now if you try to sign up using twitter you will be taken to twitter but as soon as you return back to your Grails application after authentication you will get an error. Because there is no handler for handling twitter response. Let’s create a controller which handles the response from twitter.

Step 5 : Add handler for twitter response

You may have noticed that we entered Site URL in twitter app which contains the following oauth/twitter/callback . In simple words we have to create a controller with name oauth and an action twitter inside the controller. You are free to modify the controller/action name as per your convenience. This is how my controller/action looks like :


This is it. Hope it helps you in some way.