Skip to content

Authenticate to smugmug with oAuth and c#

Some weeks ago, i tried to create a windows phone 7 smugmug app(photo browser). I had some problems with oAuth at the beginning, First, I tried the google oAuth implementation in c# with the result that the first request(AcquireRequestToken) worked, but the second request(AcquireAccessToken) failed with an invalid signature. Then i tried to implement it myself with the same result.

Even with the smugmug oAuth documentation, i found it quite hard to get it done. Some parts like the authorize parameters(public/full/read/modify) i had to figure out myself.

After some time, i found an c# oAuth class written for twitter access for cropperplugins.codeplex. With this code, i was at least able to get a proper AccessToken for smugmug. I've written a little demo application if someone else has the same problems.

To get this sample working, you only have to set you apiKey and secret. This sample will do: 1. Get a request token and a request token secret 2. Authorize the request token 3. With the request token secret, acquire a access token 4. This access token and access token secret are used for all further authentication, and should not expire until the user revokes them.

        private void AuthenticateSmugmug()
            const string apiKey = "YOURAPIKEY";//apikey from your smugmug account
            const string secret = "YOUR_SECRET";//secret from your smugmug account

        Console.WriteLine("Create new instance of OAuth Manager");
        Manager manager = new Manager(apiKey, secret);

        Console.WriteLine("Aquire a request token from smugmug");
        OAuthResponse requestToken = manager.AcquireRequestToken("", "GET");

        string oauthToken = requestToken["oauth_token"];
        Console.WriteLine(string.Format("oauthToken: {0}", oauthToken));
        string oauthTokenSecret = requestToken["oauth_token_secret"];
        Console.WriteLine(string.Format("oauthTokenSecret: {0}", oauthTokenSecret));

        //Opens your default browser and authorize your request token
        //Parameters: Access=[Public|Full], Permissions=[Read|Add|Modify]
        System.Diagnostics.Process.Start(string.Format("{0}&Access=Full&Permissions=Modify", oauthToken));

        Console.WriteLine("Please enter you credentials into the browser before continuing");
        Console.WriteLine("Press any key to continue...");

        OAuthResponse accessToken = manager.AcquireAccessToken("", "GET", oauthTokenSecret);

        Console.WriteLine(string.Format("accessToken: {0}", accessToken["oauth_token"]));
        Console.WriteLine(string.Format("accessTokenSecret: {0}", accessToken["oauth_token_secret"]));
        Console.WriteLine("Press any key to quit the application");

This is the complete source code for the oAuth sample. It's c# written in Visual Studio 10: To get this sample working, just enter your Api Key and Secret.


No Trackbacks


Display comments as Linear | Threaded

wuttrain on :


Thank you for the sample code. This is very helpful. I have a question. Do you have a sample code that uploads the image to smugmug after you get the tokens?


Buy Coursework on :

OAUTH is for verification, i.e. "you are who you say you are" and the symbol is only given when that's been pleased. You can't duplicate the symbol from a qualified customer and try to get in that way. The protection program won't allow it.

ninjaessays essays on :

Before reading this article, I hadn’t any idea about the importance of online education and I didn’t read such things before. You did well to publish it for the knowledge of the people like me and now, I understood online education’s importance.

E-commerce web development company on :

Such coding and programming are too useful for E-commerce development, before some time I live to use the PHP and SQL for the development but when I connect with C# I changed my working trend with to C#.

web development company in dubai on :

I have done coding in PHP and laravel but the coding method you have shared I am impressed to learn this. Will be trying to learn this to increase the scale of my skills and also it is the requirements of getting a good job. The man who has a mind to grow his career should learn this advanced skill to make your's career bright.

Isaca certification on :

I just want to say that you have made a great effort in making this post which is appreciable. I have learned a lot from this post which will help me a lot in future.

Brochure Design Services In UAE on :

computer hard devices are shipped with Microsoft even the HTC Corporation, Samsung, the LG, and it has released by the windows, i just love window 7 that shipped on 28 unique devices. it is confirmed and officially ac\nnounced by their manufactures.

Web Designing Company on :

I have done coding in PHP and laravel but the coding method you have shared I am impressed to learn this.

thesis help on :

Wavering! undeniably I have discovered something astonishing, This is the thing that I was checking for a long time. Thankful to you for offering this data to us. Continue sharing new posts. thesis help on :

Thank you for the information! I hope to see more updates from you.

Add Comment

You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Markdown format allowed
Form options