smartcard - Connect to a SharePoint site when IIS requires client certificates -
i have application developed in c# helps me in managing permissions on our share-point 2013 site. recently, learned may loosing our local instance , moving instance that's behind cac enforced iis. have converted 1 of test sites require certificates , have tried several way send cert iis server still
"the remote server returned , error: (403) forbidden.
below few things have tried.
var handler = new webrequesthandler(); handler.clientcertificateoptions = clientcertificateoption.automatic; handler.clientcertificates.add(pki.getclientcertificate()); handler.useproxy = false; using (var client = new httpclient(handler)) { context connection code here }
the pki.getclientcertificate method, made returns selected certificate in case cac cert. funny sharepoint designer connects without issue or prompt. on matter appreciated.
just add more things have tried
context.credentials = new sharepointonlinecredentials(uli.username, uli.password);
the uli username certificate converted username have class dose conversion. password pin converted secure string. same message when adding credentials context.
i found workable slow solution here:
the issue every time call context have send certificate chain. 1 thing changed users code following.
static void context_executingwebrequest(object sender, webrequesteventargs e) { intptr ptr = intptr.zero; x509certificate2 certificate = null; x509certificate t = null; var store = new x509store(storename.my, storelocation.currentuser); store.open(openflags.readonly | openflags.openexistingonly); // nothing if no cert found. httpwebrequest webreq = e.webrequestexecutor.webrequest; //webreq.proxy = new webproxy("http://[proxyaddress]"); //specify proxy address if need // x509certificate cert = pki.getclientcertificate(); foreach (x509certificate c in store.certificates) { webreq.clientcertificates.add(c); } }
i dumped certificates request because didn't want have prompt every time clicked something. if has more efficient way let me know.
the code below shows use of clientcontext , how validates cert
using (context = new clientcontext(siteurl)) { servicepointmanager.servercertificatevalidationcallback = delegate(object sender1, x509certificate certificate, x509chain chain, sslpolicyerrors sslpolicyerrors) { bool validationresult = true; return validationresult; }; context.executingwebrequest += new eventhandler<webrequesteventargs>(context_executingwebrequest);
//add context commands below line }
Comments
Post a Comment