My favorites | Sign in
Logo
                
Search
for
Updated Nov 16, 2008 by bittercoder
Labels: OAuth
OAuth  
DevDefined.OAuth - an OAuth consumer and provider implementation for .Net

Introduction

After looking at a few OAuth examples for .Net I was disheartened by their limited implementations, and especially a lack of a good provider implementation.

I started DevDefined.OAuth originally to accompany my REST presentation for the local .Net user group in May - but have decided to continue it's development for a little while, in a hope that it might prove useful to others trying to implementing OAuth for .Net (and because I need it for an upcoming project).

For more information on OAuth itself check out http://www.oauth.net/ and http://wiki.oauth.net/ or the google group at: http://groups.google.com/group/oauth/

Code

The code can be found here:

http://devdefined-tools.googlecode.com/svn/trunk/projects/oauth/

Guides

Issues

Still to come


Comment by bittercoder, Jul 30, 2009

kjobson is correct, if you have a look at the examples you will see that for our end to end test we use WatiN to automate the browse during the period between getting a request token, and being able to exchange it for an access token.

Incidentally I've applied some updates to the trunk to support OAuth 1.0a - I'll finish updating the provider etc. examples tomorrow and make a new release, but in the mean time this may help with your problem as well.

Comment by drb9633, Aug 06, 2009

First, thanks for producing this. I'm having an issue and am hoping you can confirm the behavior I'm seeing. I have secured a service call using the library and am just trying to hit the endpoint with a browser. I'm expecting to get a 401 with an Authentication header indicating OAuth is supported. However, what's happening is that an exception is being thrown on the service side because a token wasn't passed in. The exception happens on the GenerateSignatureBase?() call in OAuthContext. The token is null, and setting Token = string.Empty fails because the Collection behind the scenes is an HttpValueCollection?, which is read-only. Thoughts?

Comment by S.Zayas, Aug 24, 2009

drb9633: You're correct, and this is an issue for me aswell. Not only does a null value for the token generate an error, but the & sign in the end of the string is only cleaned for the generation of the basesignature. My solution is probably not perfect but this is how i do it. When creating the new OauthContext? i pass a cleaned up namevaluecollection.

      var context = new OAuthContext
                      {
                        RawUri = CleanUri(request.Url),
                        Cookies = CollectCookies(request),
                        Headers = request.Headers,
                        RequestMethod = request.HttpMethod,
                        FormEncodedParameters = request.Form,
                        QueryParameters = CleanQueryStrings(request.QueryString),
                        
                      };

And the function:

    static NameValueCollection CleanQueryStrings(NameValueCollection requestQueryString)
    {
        NameValueCollection nvc = new NameValueCollection(requestQueryString);
        if (nvc.HasKeys())
        {
            nvc.Remove(null);
        }
        return nvc;
    }

Which basically creates a new namevaluecollection which isn't readonly, removes any keys that are null and returns it.

Hope it helps.

Comment by back5576, Nov 27, 2009

I had to change UriUtility?.cs to have this work properly. Borrowed an implementation I saw in another sample:

private static readonly string UriRfc3986CharsToEscape? = new { "!", "", "'", "(", ")" };
public static string UrlEncode?(string value) {
StringBuilder? escaped = new StringBuilder?(Uri.EscapeDataString?(value));
// Upgrade the escaping to RFC 3986, if necessary. for (int i = 0; i < UriRfc3986CharsToEscape?.Length; i++) {
escaped.Replace(UriRfc3986CharsToEscape?i?, Uri.HexEscape?(UriRfc3986CharsToEscape?i?0?));
}
return escaped.ToString?();
}

Without this change, the oauth signatures were invalid if URL contained cyrillic characters.

Thought this might help others.

Comment by back5576, Nov 27, 2009

Sign in to add a comment
Hosted by Google Code