{"id":1670,"date":"2011-01-12T22:09:42","date_gmt":"2011-01-12T20:09:42","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=1670"},"modified":"2022-10-21T18:18:12","modified_gmt":"2022-10-21T16:18:12","slug":"2-legged-oauth-with-imap","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/2-legged-oauth-with-imap","title":{"rendered":"2-legged OAuth with IMAP"},"content":{"rendered":"\n<p>OAuth is an open protocol to allow secure API authorization in a simple and standard method from desktop and web applications.<\/p>\n\n\n\n<div class=\"well\">This article describes generic OAuth class.<br><strong>If you are using Gmail<\/strong> please read <a href=\"\/blog\/2-legged-oauth-with-gmail\">2-legged OAuth authentication with Gmail<\/a>.<\/div>\n\n\n\n<p>Remember to add reference to Mail.dll <a href=\"\/mail\">.NET IMAP component<\/a> and appropriate namespaces.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n\/\/ C#\n\nusing Limilabs.Client.Authentication;\nusing Limilabs.Client.IMAP;\n\nstring consumerKey = &quot;your_domain.com&quot;;\nstring consumerSecret = &quot;your_oauth_consumer_secret&quot;;\nstring emailAccount = &quot;address@your_domain.com&quot;;\n\nusing (Imap client = new Imap())\n{\n    client.ConnectSSL(&quot;imap.gmail.com&quot;);\n\n    string imapUrl = string.Format(\n        &quot;https:\/\/mail.google.com\/mail\/b\/{0}\/imap\/?xoauth_requestor_id={1}&quot;,\n        emailAccount,\n        HttpUtility.UrlEncode(emailAccount));\n\n    string oauthImapKey = OAuth.ForUrl(imapUrl)\n        .Consumer(consumerKey, consumerSecret)\n        .SignatureMethod(SignatureType.HMACSHA1)\n        .Sign()\n        .GetXOAuthKey();\n\n    client.LoginOAUTH(oauthImapKey);\n\n    \/\/...\n\n    client.Close();\n}\n<\/pre><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: vb; title: ; notranslate\" title=\"\">\n' VB.NET\n\nImports Limilabs.Client.Authentication\nImports Limilabs.Client.IMAP\n\nDim consumerKey As String = &quot;example.com&quot;\nDim consumerSecret As String = &quot;secret&quot;\nDim emailAccount As String = &quot;pat@example.com&quot;\n\nUsing client As New Imap()\n    client.ConnectSSL(&quot;imap.gmail.com&quot;)\n\n    Dim imapUrl As String = String.Format( _\n        &quot;https:\/\/mail.google.com\/mail\/b\/{0}\/imap\/?xoauth_requestor_id={1}&quot;, _\n        emailAccount, _\n        HttpUtility.UrlEncode(emailAccount))\n\n    Dim oauthImapKey As String = OAuth.ForUrl(imapUrl) _\n        .Consumer(consumerKey, consumerSecret) _\n        .SignatureMethod(SignatureType.HMACSHA1) _\n        .Sign() _\n        .GetXOAuthKeyForImap()\n\n    client.LoginOAUTH(oauthImapKey)\n\n    '...\n\n    client.Close()\nEnd Using\n<\/pre><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>OAuth is an open protocol to allow secure API authorization in a simple and standard method from desktop and web applications. This article describes generic OAuth class.If you are using Gmail please read 2-legged OAuth authentication with Gmail. Remember to add reference to Mail.dll .NET IMAP component and appropriate namespaces. \/\/ C# using Limilabs.Client.Authentication; using [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[15,28,77,41,57,68],"class_list":["post-1670","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-c","tag-imap","tag-imap-component","tag-oauth","tag-vb-net","tag-xoauth"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1670"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=1670"}],"version-history":[{"count":9,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1670\/revisions"}],"predecessor-version":[{"id":6383,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1670\/revisions\/6383"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=1670"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=1670"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=1670"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}