authenticate through linq-to-twitter

Nov 28, 2012 at 5:02 PM
Edited Nov 28, 2012 at 9:45 PM

Hello.  I'm trying to get LINQ To Twitter to work.  I'm using ASP.Net MVC's OAuthWebSecurity.  I can successfully authenticate the Twitter user.  Here's my code:

OAuthWebSecurity.RegisterTwitterClient
(
	consumerKey: "XXXX",
	consumerSecret: "YYYY",
	displayName: "Twitter",
	extraData: new Dictionary<string, object>
           	{
           		{ "Icon", "~/Content/images/twitter.png" },
			{ "ConsumerKey", "XXX" }, 
			{ "ConsumerSecret", "YYYY" }
           	}
);

I'm including consumerKey and consumerSecret in the extraData so I can retrieve the values and use them for LINQ To Twitter's InMemoryCredentials further into my code in order to query Twitter for data.

OAuthWebSecurity for Twitter is returning accessToken, userName, name, and description from Twitter upon authentication.  I'm storing these values in my database.  I've noticed I'm not getting OAuthToken from Twitter.

Further into my code where I need to get data from Twitter, I'm doing the following: (note: twitterUser is my user containing authentication data from database)

//GET TWITTER'S CONSUMER KEY, CONSUMER SECRET
var authenticationClientData = OAuthWebSecurity.RegisteredClientData.Where(p => p.DisplayName == "Twitter").FirstOrDefault();
var consumerKey = authenticationClientData.ExtraData["ConsumerKey"].ToString();
var consumerSecret = authenticationClientData.ExtraData["ConsumerSecret"].ToString();

var mvcAuthorizer = new MvcAuthorizer
{
	Credentials = new InMemoryCredentials
	{
		ConsumerKey = consumerKey,
		ConsumerSecret = consumerSecret,
		AccessToken = twitterUser.Accesstoken
	}
};

var twitterCtx = new TwitterContext(mvcAuthorizer);

This seems to be working until I call this code:

var friendList = (from friend in twitterCtx.SocialGraph
			where
			friend.Type == SocialGraphType.Friends
			&& friend.ScreenName == twitterUser.UserName
			 select friend).ToList();

I get "Bad Authentication Data" error.  I researched your discussions and found this link: http://linqtotwitter.codeplex.com/discussions/403709

It's apparent to me that I need to add OAuthToken to InMemoryCredentials.  What should I use for OAuthToken?  I downloaded MVCFriendshipsDemo MVC app and see that you are calling "auth.CompleteAuthorization(Request.Url);"  I can find OAuthToken in the auth variable after CompleteAuthorization fires.

So, I'm stumped.  I'm authenticating using MVC's OAuthWebSecurity process.  I'm getting data back from Twitter and am saving it in my database, however, I'm missing OAuthToken.  Perhaps MVC's implementation of OAuthWebSecurity has a bug in that OAuthToken is not returned.

Maybe I have to somehow incorporate "auth.CompleteAuthorization(Request.Url);" into MVC's OAuthWebSecurity process in order to get OAuthToken.  This smells bad though.

Please help.  I need this to work.

 

*** UPDATE ***

After reading Twitter Docs I found "Use the access token string as your "<tt>oauth_token</tt>"".  So I tried this:

var mvcAuthorizer = new MvcAuthorizer
{
	Credentials = new InMemoryCredentials
	{
		ConsumerKey = consumerKey,
		ConsumerSecret = consumerSecret,
		AccessToken = twitterUser.Accesstoken,
		OAuthToken = twitterUser.Accesstoken
	}
};

 

I'm using user's AccessToken that I'm saving in database for AccessToken AND oAuthToken for InMemoryCredentials.  I'm still getting an error though.  I'm now getting:

{"The remote server returned an error: (401) Unauthorized."} {"Could not authenticate you"}

If I have gone through the authentication process and have a valid accessToken, then why am I getting this error?  The error message is a little confusing.  The exception from LinqToTwitter says "Could not authenticate you" however the inner error is 401 Unauthorized.  Authorization and Authentication are different things.

Here's the complete error:

LinqToTwitter.TwitterQueryException was unhandled by user code
  Message=Could not authenticate you
  Source=LinqToTwitter
  ErrorCode=32
  HttpError=ProtocolError
  StackTrace:
       at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33()
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
  InnerException: System.Net.WebException
       Message=The remote server returned an error: (401) Unauthorized.
       Source=LinqToTwitter
       StackTrace:
            at LinqToTwitter.TwitterExecute.QueryTwitter[T](Request request, IRequestProcessor`1 reqProc)
       InnerException:

Nov 28, 2012 at 10:42 PM
Edited Nov 28, 2012 at 10:45 PM

I think I figured it out.  I changed the ExternalLoginCallback method of my AccountController to use the following code if I'm authenticating via Twitter:

	if (providerId == (int)OAuthWebSecurityProviderType.Twitter)
	{
		var authenticationClientData = OAuthWebSecurity.RegisteredClientData.Where(p => p.DisplayName == "Twitter").FirstOrDefault();
		var consumerKey = authenticationClientData.ExtraData["ConsumerKey"].ToString();
		var consumerSecret = authenticationClientData.ExtraData["ConsumerSecret"].ToString();

		IOAuthCredentials credentials = new SessionStateCredentials();

		if (credentials.ConsumerKey == null || credentials.ConsumerSecret == null)
		{
			credentials.ConsumerKey = consumerKey;
			credentials.ConsumerSecret = consumerSecret;
		}

		var auth = new MvcAuthorizer
		{
			Credentials = credentials,
		};

		auth.CompleteAuthorization(Request.Url);

		if (!auth.IsAuthorized)
		{
			return auth.BeginAuthorization(Uri(Request.Url.ToString()));
		}
		else
		{
		   //... PROCESS RESULTS
		}
	}
	else
    {
		//...HANDLE OTHER AUTHENTICATION TYPES (FACEBOOK, ETC) 
    }

It appears to me that ASP.NET MVC's OAuthWebSecurity.VerifyAuthentication is returning bad data.  It's AccessToken value was the same value as MvcAuthorizer's OAuthToken value.  However, MvcAuthorizer's AccessToken value was something totally different.  This approach seems to be working as I can query Twitter and retrieve friends and followers.

Any ideas as to what's going on?

Thanks

Tom

Coordinator
Nov 28, 2012 at 11:29 PM

Hi Tom,

Thanks for the info and following up. I haven't looked closely at OAuthWebSecurity yet, but plan to do so to see if it can make the OAuth experience better. The new WebAuthorizationBroker in Windows 8 is phenomenal and I wrapped a WinRtAuthorizer around it - so I'm hoping for the best here, which could greatly improve the experience - fingers crossed.

Today, both the BeginAuthorization and CompleteAuthorization are necessary. BeginAuthorization gets a request token and sends the user to the Twitter Authorization page, after the user authorizes your application Twitter redirects them back to the callback (same page as BeginAuthorization by default or can be specified by parameter to BeginAuthorization), and you call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F0dGFjaG1l bnRzIHdpbGwgYmUgcmVtb3ZlZCBmcm9tIGVtYWlscy4gQW55IHBvc3RzIHRvIHRoaXMgZGlzY3Vz c2lvbiB3aWxsIGFsc28gYmUgYXZhaWxhYmxlIG9ubGluZSBhdCA8YSBocmVmPSJodHRwOi8vQ29k ZVBsZXguY29tIj5Db2RlUGxleC5jb208L2E+PC9wPiA8L2Rpdj4gIDwvZGl2PjwvYmxvY2txdW90 ZT48L2JvZHk+PC9odG1sPg= --Apple-Mail-1274C73F-BC49-4BEC-A518-9946C12A3156--
Coordinator
Nov 29, 2012 at 1:16 AM
<warning:humor>
    I don't think Bing has a translator for that one.
</warning:humor>

 :)

@JoeMayo

Nov 29, 2012 at 1:06 PM

LOL.  I guess codeplex doesn't like Apple.  Here's what I attempted to send via iPhone:

Hi Joe. Thanks for the reply.  OAuthWebSecurity is a step towards having a unified approach to interacting with all of the different OAuth providers.  OAuthWebSecurity supports Facebook, Twitter, LinkedIn, Yahoo, Google, and Microsoft. I'm developing an app where a user can use any if those approaches for authentication.  It's a step in the right direction.

I'm not sure if MS OAuthWebSecurity has a bug where it's not returning the right set of data to further interact with Twitter, or if LINQ for Twitter is imposing an additional data element. It's clear from my testing that the data each returns is different. 

My hope was to have a unified approach for interacting with OAuth providers.   Right now I have a big "if" in my code for treating Twitter differently.  It's ok for now as I can move forward with my development. 

Thanks for your work with LINQ To Twitter.  I'm looking forward to using it.
Coordinator
Nov 29, 2012 at 1:20 PM

Just a note - if you can get the credentials from OAuthWebSecurity, or any other OAuth provider, just fill in all 4 credentials for the authorizer. If LINQ to Twitter has all 4 credentials, it won't start the authentication sequence, but it just uses the credentials to sign Twitter requests. That means you won't need to call BeginAuthorization/CompleteAuthorization.

Joe

Nov 29, 2012 at 1:45 PM

Therein lies the rub.  OAuthWebSecurity for Twitter only returns accessToken, not OAuthToken.  The value that OAuthWebSecurity returns for accessToken is not the same value that is returned via mvcAuthorizer.CompleteAuthorization for accessToken.  It seems the OAuthToken value from mvcAuthorizer.CompleteAuthorization is the same value as accessToken from OAuthWebSecurity.  So, it appears the 2 approaches to OAuth security for Twitter are not on the same page.

Hopefully you will be able to test OAuthWebSecurity for Twitter and compare it to how LINQ To Twitter works for authentication.


Thanks

Tom

Jan 30, 2013 at 7:48 AM
Edited Jan 30, 2013 at 8:00 AM

Tom, did you ever solve this? 

I started with the Linq-to-twitter today and ran into the same exact problem.

 

Thanks.

Feb 2, 2013 at 7:46 AM
Update:

Tom, I solved this using these steps:

1) Extracting the oauth_token_secret from OAuthWebSecurity by designing my own TokenManager. You can register the token manager when you register your Twitter client in OAuthWebSecurity.RegisterClient.

2) I assigned my values to credentials as follows:
          if (credentials.ConsumerKey == null || credentials.ConsumerSecret == null)
                {
                    credentials.ConsumerKey = consumerKey;
                    credentials.ConsumerSecret = consumerSecret;
                    credentials.AccessToken = oauth_token_secret;
                    credentials.OAuthToken = oauth_token;
                }
3) This way I was able to bypass both CompleteAuthorization and BeginAuthorization steps and create a nicer user experience.

Soon I will blog on my solution and put the source code out there.

Hope this helps.
Nov 27, 2013 at 10:03 PM
Can I get a copy of the above code, I am having the same problem, or did a later version of LinqToTwitter resolve this?