title: Google OAuth 2.0 Authentication in a C# Installed Application
body: <p>I am trying to add OAuth authentication to a C# program that works with Gmail using IMAP.  The actual AUTHENTICATE XOAUTH2 command in IMAP is working perfectly if I obtain an Access Token from the OAuth 2.0 Playground.  However my attempts to enable the program to obtain an Access Token itself are stalled.  I have read the RFCs and have a bit of an idea of what is going on but am still struggling to make practical sense of it all.  So I am asking for help.</p>
  
  <p>The code I am failing with is as follows, copied from a sample <a href="https://code.google.com/p/google-api-dotnet-client/wiki/OAuth2#Installed_Applications" rel="nofollow">here</a>:</p>
  
  <pre><code>ClientSecrets clientSecrets = new ClientSecrets{ClientId = myClientID, ClientSecret = myClientSecret};
  
  string[] scopes = new string[] { "https://mail.google.com" };
  
  Google.Apis.Auth.OAuth2.UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                  clientSecrets, scopes, "user", CancellationToken.None).Result;
  </code></pre>
  
  <p>When I run this, I receive an error message in my browser saying:</p>
  
  <pre><code>Error: redirect_uri_mismatch
  
  The redirect URI in the request: http://localhost:59904/authorize/ did not match a registered redirect URI
  </code></pre>
  
  <p>I understand that I need to set a redirect URI of "urn:ietf:wg:oauth:2.0:oob" but I am at a loss to figure out how to do this and to understand why the sample fails to do so.</p>
  
  <p>Many thanks for any assistance...</p>