This project is read-only.

Get Twitter Authentication from external module

As described here

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;

        public 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 => Console.WriteLine(
                    "Friend: {0}\nTweet: {1}\n",

            return null;

Last edited Feb 27, 2011 at 8:08 PM by Jetski5822, version 2


Jetski5822 Apr 15, 2012 at 11:45 PM 
IOAuthTwitterAuthorizer has been renamed to IOAuthProviderTwitterAuthenticator