Linq2Twitter, Open Authentication module and Orchard CMS

#orchard #openauthentication

Posted by admin on September 01, 2019

Note : The Open authentication module is a work in progress this may change, though I thought I would blog about it because I thought it was cool Smile Also all code is on Dev branch at the moment.

Linq2Twitter is a really cool project that allows you to easily interact with twitter, so how do you authenticate with this module without having to worry about authentication? (bit weird huh) In comes the OpenAuthentication module for Orchard CMS.

First you need to have a twitter association set up in Orchard, thus because IUser is required.

1. First set up Twitter association..

Click the ‘Associated Accounts’ under the Users section on the admin page. Next click Add Account


Then select ‘Twitter’ (yes the pic sucks at the moment)


This will redirect you to the twitter page where you can select ‘allow’ or ‘deny’


Select ‘Allow’ because you know my module is awesome. This will return you back to the orchard Admin page.


Yes the account is not displaying correctly. but that will be worked out…  Someone please log a bug Smile

  • Account Set up

2. Next thing, over to Linq2Twitter. The Open Authentication module has an interface called IOAuthTwitterAuthorizer. This will allow you to get the authorizer for a particular user.

The key to getting the authorizer is to use the GetAuthorizer(User Here) method where you pass thru the IUser (hence why you need the user setup in orchard).

I have done a code sample below. Easy right??

using System;
using System.Linq;
using System.Web.Mvc;
using LinqToTwitter;
using NGM.OpenAuthentication.Core.OAuth;
using Orchard;

namespace NGM.Twitter.Controllers {
 public class HomeController: Controller {
  private readonly IOAuthTwitterAuthorizer _twitterAuthorizer;
  private readonly IOrchardServices _orchardServices;

  public HomeController(IOAuthTwitterAuthorizer twitterAuthorizer, IOrchardServices orchardServices) {
   _twitterAuthorizer = twitterAuthorizer;
   _orchardServices = orchardServices;

  ViewResult RetrieveTweets() {
   var twitterCtx = new TwitterContext(_twitterAuthorizer.GetAuthorizer(_orchardServices.WorkContext.CurrentUser));

   var tweets =
    from tweet in twitterCtx.Status
   where tweet.Type == StatusType.Friends
   select tweet;

    tweet = & gt; Console.WriteLine(
     "Friend: {0}\nTweet: {1}\n",

   return null;

Hope this help people

Codeplex project :

p.s. don't forget to enable the Open Authentication module!!!