Does Windows Phone 8.1 support adding a client certificate to an HTTP web request? I'm trying to do something similar to the following, but I can't seem to determine what (if any) is the equivalent to this on WP8.1:
System.Net.HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.ClientCertificates.Add(certificate);
Thanks.
On the taskbar, click Start, and then click Control Panel. In Control Panel, click Programs and Features, and then click Turn Windows Features on or off. Expand Internet Information Services, then select Client Certificate Mapping Authentication, and then click OK.
The Certificate Manager tool for the local device appears. To view your certificates, under Certificates - Local Computer in the left pane, expand the directory for the type of certificate you want to view. To view certificates for the current user, open the command console, and then type certmgr. msc.
On iOS, certificates are stored in the publisher keychain. On Android, they are stored in the system keychain.
I assume that you have already put the client certificate in app certificate store. If not this is how you will have to do that 1) Download the PFX file. 2) Install it in the App's certificate store using the following way
await CertificateEnrollmentManager.ImportPfxDataAsync(certString, "Your_PFX_Password", ExportOption.Exportable, KeyProtectionLevel.NoConsent, InstallOptions.None, friendlyName);
3) The next step is to look for the certificate in certificate store. This is done as below
CertificateQuery certQuery = new CertificateQuery();
certQuery.FriendlyName = friendlyName;
IReadOnlyList<Certificate> certs = await CertificateStores.FindAllAsync(certQuery)
The certs[0] will have the certificate
4) To attach the certificate to HTTP request
HttpBaseProtocolFilter protolFilter = new HttpBaseProtocolFilter();
protolFilter.ClientCertificate = certs[0] //from previous step
HttpClient client = new HttpClient(protolFilter)
Point to note is you should not use System.Net.htpp.HttpClient. Instead you should you Windows.Web.Http.HttpClient.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With