Last active
April 22, 2016 09:23
-
-
Save atifaziz/5664067 to your computer and use it in GitHub Desktop.
Real pre-authentication with JsonRpcClient from Jayrock against Nutshell CRM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://groups.google.com/forum/?fromgroups#!topic/jayrock/FQjHPb_QswU | |
using System; | |
using System.Net; | |
using System.Text; | |
static class Program | |
{ | |
static void Main() | |
{ | |
var client = new JsonRpcClient | |
{ | |
Url = "https://app01.nutshell.com/api/v1/json", | |
PreAuthenticate = true, | |
Credentials = new NetworkCredential("jim@demo.nutshell.com", "43c789d483fd76547b1f157e3cf5e580b95b9d8c"), | |
}; | |
var lead = client.Invoke(typeof(object), "getLead", new { leadId = 1000 }); | |
Console.WriteLine(lead); | |
} | |
} | |
public class JsonRpcClient : Jayrock.JsonRpc.JsonRpcClient | |
{ | |
protected override WebRequest GetWebRequest(Uri url) | |
{ | |
var request = base.GetWebRequest(url); | |
NetworkCredential creds; | |
if (PreAuthenticate && null != (creds = Credentials.GetCredential(url, "Basic"))) | |
{ | |
var basicCreds = creds.UserName + ":" + creds.Password; | |
var credsBytes = Encoding.UTF8.GetBytes(basicCreds); | |
var encodedCreds = Convert.ToBase64String(credsBytes); | |
request.Headers["Authorization"] = "Basic " + encodedCreds; | |
} | |
return request; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment