I am writing an MVC4 Web Application that has to query the Twitter Version 1.1 API. Built into MVC4, I can use the “Sign in with Twitter” function when I just activate OAuthWebSecurity.RegisterTwitterClient in AuthConfig.cs. This then authenticates the Twitter login, but what I want to do is authorize the user so that I can make API v1.1 calls on behalf of the user.
I have found this post on Stack Overflow which uses custom classes to address something different (the force_login parameter issue), but I have used these classes and changed the UserAuthorizationEndpoint to point to oauth/authorize. I changed this line of code:
UserAuthorizationEndpoint = new MessageReceivingEndpoint("https://api.twitter.com/oauth/authenticate", HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest),
UserAuthorizationEndpoint = new MessageReceivingEndpoint("https://api.twitter.com/oauth/authorize", HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest),
It works for the authorization, which means now my application authorizes the Twitter user. However, when I make calls to the API v1.1, I get the ‘(401) Unauthorized’ error. This is the code I use for the call:
var var1 = WebWorker.PrepareAuthorizedRequest(new MessageReceivingEndpoint("https://api.twitter.com/1.1/followers/ids.json?cursor=-1screen_name=sitest reams", HttpDeliveryMethods.GetRequest), accessToken); var var2 = var1.GetResponse();
I think I also need the oauth_token_secret for the call to be authorized.
Can DotNetOpenAuth give me the oauth_token_secret? Can I then use
WebWorker.PrepareAuthorizedRequest to also send the oauth_token_secret?
I have also found this post on Stack Overflow which says I can’t use DotNetOpenAuth for this. However, the DotNetOpenAuth code has been updated since, and I want to know if it now caters for what I want to do, which is in essence a very simple thing: allow a user to login on my web application using Twitter, and then allow my web application to see the user’s followers.
So it boils down to this: can I use DotNetOpenAuth in MVC4 to authorize the user and then call the Twitter API v1.1 on the user’s behalf, for instance to GET followers/ids. If possible, how do I do it?