This project has moved and is read-only. For the latest updates, please go here.

MVC Authentication

Jun 10, 2012 at 11:12 PM
Edited Jun 10, 2012 at 11:13 PM



Firstly I hate posting these "i can't get it to work properly" posts, but I have spent a number of hours on this, started clean projects from scratch, and read and searched the site over and over and come up short.

If I follow the basic implementation here....

I can authorise the application and the controller returns 



, and the twitterCtx is populated properly, and has proper twitterCtx.UserName etc.


However, ,if I theen reload the page, I get 


but the twitterCtx.UserName isn't complete and holds no info. The action runs normally, and credentials holds all four items correctly, but I just can't see how/why I don't get a properly fulfilled twitterCtx on subsequent calls to the action. _______
I don't know if it is my understanding of the process, but even with the 4 credential elements fulfilled, I can't get an proper TwitterContext without completely reauthorising the app.
Sincerely look forward to hearing any input from people on this... and only too happy to be told I am an idiot and let me know what I should be looking for !

Jun 11, 2012 at 12:47 AM


The UserName assigned to TwitterContext is only populated when LINQ to Twitter does the request for an Access Token from Twitter during the OAuth authentication process.  Therefore, your observations are correct in that the only way this populates is if you re-authorize each time.

Once you have credentials from an initial OAuth authentication, grab the UserName also and store it.

The reason you don't get the UserName on subsequent calls is because the Access Token is already one of the credentials you've populated the Authenticator with.  LINQ to Twitter already has the access token (all 4 credential tokens), it doesn't need to do OAuth authentication anymore, which is an intentional design for efficiency, performance, scalability, and simplicity.  For these reasons, you probably don't want LINQ to Twitter making extra calls to Twitter.

Thanks for posting - these are good discussions that make me think about things more.


Jun 11, 2012 at 9:11 AM

Thanks Joe,

Nice to know it was working as it should all along ! I'll have a little play with that this morning with that in mind. Easy enough workaround as I have an authentication ViewModel I was using for the views, so I'll just populate that on the first authenticatuin and then refer back to that.