Linkedin oAuth desktop c# sample embedded webBrowser

I’ve created and uploaded some sample code for using Linkedin’s oauth library in a c# desktop app.  Faith Yasar’s c# code was my starting point.  A bit of a refactor of the oAuth librarie to include the oauth_callback parameter was needed, as well as code for displaying the login dialog.

Code can be found here in a forum post I made on linkedin.

The code contained includes a test harness as well as the oauth libraries for oauth login dance and Linkein API requests.  Oauth login is handled with an embedded webBrowser which is shown modally for the user to login.  Upon login completion, dialog will be closed and the token and verifier will be available from the dialogs property.

To use the code, simply Add your Linkedin consumer secret and Consumer key to the OauthLinkedIn.cs file:

private string _consumerKey = "ENTER_YOUR_CONSUMER_KEY";
private string _consumerSecret = "ENTER_YOUR_CONSUMER_SCRET";

Then you can make api calls following a few steps:

OAuthLinkedIn _oauth = new OAuthLinkedIn();
String requestToken = _oauth.getRequestToken();
String accessToken = _oauth.getAccessToken();</div>

Hope that helps

RE: Climate jihadists want Canada to be embarrassed, but for what?

Dear Gary Lamphier,

A nerve is always struck when I read articles such as your “Climate jihadists want Canada to be embarrassed, but for what?” article appearing in the Edmonton Journal December 12th, 2009.
My annoyance isn’t related to my agreement or disagreement with some of your points; which as best as I can tell are:
a) the Mayor of Toronto should be more embarrassed about other issues,
b) that Canadians shouldn’t be embarrassed  about our environmental issues, and
c) that environmental summits are nothing but glorified holidays paid for by taxpayers.

My issue is with your strategy for making these points.

One wrong is not made right because you have a bigger wrong.  Similarly one wrong is not made right because someone else has a bigger wrong.  These arguments stopped making sense around the age of 8 for me.  So you pointing out that Toronto endured a garbage strike, and that China’s carbon emissions negate any progress we’ll make is irrelevant.  That is of course if I’m correct that you’re suggesting we shouldn’t be so embarrassed about our environmental leadership.

I’m also annoyed with your use of buzz words to invoke emotions to your readers.  Jihadist?  Do you know what this word means?  I suspect you do; actually I’m positive you do.  But I’m also positive that you know full well what your readers emotional response to a word that’s become so loaded will be.  I’ll mention that from my memory of Religious studies 100, “Jihadist” is a term used to describe a Muslim who favors or supports the jihad.  Jihad is an Islamic term, to represent a religious duty of Muslims.  But for most of us westerners, “Jihadist” = crazy fenatic who fly plains into buildings.  I imagine you’ll succeed in engaging readers with your use of this, but I fail to see the logic in comparing David Miller to a jihadist.  Maybe this Climate jihadist is a common term that I’m just unfamiliar with.  Are you simply saying that his duty is to advance environmental issues?

As an aside,  a personal pet peeve is the use of parenthesis to convey sarcasm.  So perhaps you’re use of this strategy got me off on the wrong foot.

I guess you’re asking why David Miller is embarrassed.  I can’t speak for him or any fellow Canadian, but I can tell you what I’m embarrassed about.

And I’m also a little embarrassed to say that I’m from a city where articles like yours make it to press.


David Quail

“Burn fat not gas” launched

“Burn Fat not Gas” just came alive tonight at not gas logo

Right now, the web site is incredibly simple – It’ll determine the environmental, economic, and health savings you’d benefit from by biking to work rather than driving based on averages.

The site is really a product of a) me wanting to try my hand at a simple Ruby on Rails project, b) my increasing inner rage towards the Alberta Oil sands after more studies and c) having a few free evenings.

Given all the time in the world, I’d love to support a community of passionate cyclists with forums, merchandise, commuting maps, challenges and other features.

In the mean time I’d love to hear what you think.

Keep cycling …

Popular iPhone apps deliver value in 10s or less

I recently made an observation when taking inventory of the iPhone apps I have installed.

I noted that any app I use with any regularity will provide me with value in 10 seconds or less.  If it takes longer, I’d just as soon crack open the laptop and use the web/desktop version … or be distracted by some other app on my iPhone.  While there’s plenty of apps installed (at least 4 pages full), the only ones I use are Shazam, Mail, Contacts, Google Maps, Tweetie, Facebook, Weather, Showtimes …. all apps that I can get data from within 10 seconds.

It seems that the iPhone has tapped into our North American attention deficit selves.  I find myself busting out my iPhone any time I’m without stimulation … even when waiting for the traffic light to turn green.  The iPhone and it’s apps owe a lot of their success to an ability to fill the gaps in our day to day lives – it’s candy to the attention deficit.  And to me, there’s nothing better than an app that can entertain me in as little as 10 seconds.

Effects of alternative energy souces

I just finished reading Clean tech revolution.  Good book, excites me to think of technology advancing green initiatives and the role that a technologist can play.

When thinking about tapping into renewable energy sources – solar, geothermal, wind, tidal, etc. – I can’t help but wonder what the effects on nature will be when harvesting these natural sources.  I’m clearly a novice when it comes to geo-physics but you’d have to think these energy sources have huge roles in heating the earth, conducting air and ocean current, controlling weather, etc.  Would we be using so little of this energy that it doesn’t make a difference?  I’d love to read more research on this.

To me, it’s still pretty simple.  Humans demand WAY too much energy from the earth.  Whether you’re taking energy locked away in fossil fuels, or from wind blowing by your house to power an automobile … it’s going to have an effect on our ecosystem.  Ultimately, the only real clean watt is the Negawatt … the watt you don’t use.

oAuth authorization callback on the iPhone with WebView

There was a bit of chatter a while back about handling oAuth on the iPhone; in particular security balances sending a user to the website using Safari vs an embedded WebView.  Mike’s blog post discusses this so I won’t repeat, other than to say that I think either solution (webView or Safari) is open for spoofing.  An app developer could spoof an auth and grab creds in either case pretty easily … so I’ve chosen to optimize for user experience by implemented an oAuth webView for our app.

Here’s some of the relevant code for launching to an authorize website and handling the response.

* Our app uses oAuthConsumer library

* Our implimentation was against linkedin oauth which meant that I needed to pass the oauth_callback in our request token request by setting the oauth_callback parameter there rather than the authorize URL

In other words, our requestToken method looks something like the following:

OAMutableURLRequest                *request = [[[OAMutableURLRequest alloc] initWithURL: self.requestTokenURL consumer: self.consumer token:nil realm:nil signatureProvider: nil] autorelease];
 if (!request) return;
 [request setHTTPMethod: @"POST"];
 [request setParameters: [NSArray arrayWithObject: [[[OARequestParameter alloc] initWithName: @"oauth_callback" value: kLinkedInCallbackUrl] autorelease]]];
 OADataFetcher                *fetcher = [[[OADataFetcher alloc] init] autorelease];
 [fetcher fetchDataWithRequest: request delegate: self didFinishSelector: @selector(setRequestToken:withData:) didFailSelector: @selector(outhTicketFailed:data:)];

With the request token set, we’re able to pass this to the authorize url and it will return to our custom url

/*Create the request object for the linkedin URL*/

if (!_requestToken.key && _requestToken.secret) return nil;    // we need a valid request token to generate the URL

 OAMutableURLRequest            *request = [[[OAMutableURLRequest alloc] initWithURL: self.authorizeURL consumer: nil token: _requestToken realm: nil signatureProvider: nil] autorelease];

 [request setParameters: [NSArray arrayWithObject: [[[OARequestParameter alloc] initWithName: @"oauth_token" value: _requestToken.key] autorelease]]];

/*Load the webview with this request*/

[_webView loadRequest: request];

/*Check the response for a custom uri and redirect if it's set*/
- (BOOL) webView: (UIWebView *) webView shouldStartLoadWithRequest: (NSURLRequest *) request navigationType: (UIWebViewNavigationType) navigationType {
 NSData                *data = [request HTTPBody];
 char                *raw = data ? (char *) [data bytes] : "";
 NSURL* url = request.URL;

 if ([url.scheme isEqualToString:@"liconnect"]) {
 [_spinner stopAnimating];
 if ([url.resourceSpecifier isEqualToString:@"cancel"]) {
 if ([_delegate respondsToSelector:@selector(OAuthLinkedInAuthorizeViewFailed:)]) {
 [_delegate OAuthLinkedInAuthorizeViewFailed:self];
 else {
 [self dialogDidSucceed:url];

 return NO;

 if (raw && strstr(raw, "cancel=Deny")) {
 [self denied];
 return NO;
 if (navigationType != UIWebViewNavigationTypeOther) _webView.alpha = 0.1;
 return YES;

/*Strip out the token and auth_verifier from the url*/

- (void)dialogDidSucceed:(NSURL*)url {
 NSString* q = url.query;
 NSRange verifier_start = [q rangeOfString:@"oauth_verifier="];

 NSRange start = [q rangeOfString:@"auth_token="];
 if (start.location != NSNotFound) {
 NSRange end = [q rangeOfString:@"&"];
 NSUInteger offset = start.location+start.length;
 NSString* token = end.location == NSNotFound
 ? [q substringFromIndex:offset]
 : [q substringWithRange:NSMakeRange(offset, end.location-offset)];

 NSString* verifier = [q substringFromIndex:verifier_start.location+verifier_start.length];
 if (token&&verifier) {
 if ([_delegate respondsToSelector:@selector(requestTokenReceived:withVerifier:)]){
 [_delegate requestTokenReceived:token withVerifier:verifier];
 if ([_delegate respondsToSelector:@selector(OAuthLinkedInAuthorizeViewFailed:)]){
 [_delegate OAuthLinkedInAuthorizeViewFailed:self];
 }        }
 [self removeFromSuperview];

You’re done.  You’ve now got your oauth_verifier and your access token all lined up to store away or make immediate calls to the api.