c# - Multiple certificates with HttpClient -


i building windows phone 8.1 app allows azure users view subscription/services using azure service management api. authentication done using management certificate , certificate attached requests api. works fine single user. problem arises when try include feature multiple subscriptions. able install certificate in certificate store , retrieve it. problem arises when send request api. though attaching correct certificate, 403 forbidden error. here code i've used.

public async task<certificate> getcertificate() {           await certificateenrollmentmanager.importpfxdataasync(certificate, "", exportoption.exportable, keyprotectionlevel.noconsent, installoptions.none, subscriptionid);           certificatequery query = new certificatequery();           query.friendlyname = subscriptionid;           var c = await certificatestores.findallasync(query);           return c[0]; }  public async task<httpresponsemessage> sendrequest(string url,string version) {         httpresponsemessage response = null;         try         {             httpbaseprotocolfilter filter = new httpbaseprotocolfilter();             filter.clientcertificate = await getcertificate();             httpclient client = new httpclient(filter);             httprequestmessage request = new httprequestmessage();             request.requesturi = new uri(url);             request.headers.add("x-ms-version", version);             response = await client.sendrequestasync(request, 0);             return response;         }         catch(exception e)         {             var status=windows.web.weberror.getstatus(e.hresult);             if (status == weberrorstatus.cannotconnect)                 throw new exception("cannot connect internet. check connection.");             else if (status == weberrorstatus.disconnected)                 throw new exception("connection disconnected.");             else if (status == weberrorstatus.serviceunavailable)                 throw new exception("server unavailable");             else if (status == weberrorstatus.connectionreset)                 throw new exception("connection reset.");             else if (status == weberrorstatus.badgateway)                 throw new exception("bad gateway.");             else if (status == weberrorstatus.internalservererror)                 throw new exception("internal server error occurred");             else if (status == weberrorstatus.hostnamenotresolved)                 throw new exception("check network connection. host name not resolved.");         }         return response;   } 

does windows phone os have restrictions on certificates app?

while not directly answering how deal certificate issue, suggest workaround work better.

use oauth authorization bearer token , azure ad authentication service api, instead of certificates.

thus, instead of managing multiple certificates, use adal token azure ad. , single token receive valid subscriptions user has access to.

you can read more on authenticating service management api calls azure ad here.

and can learn more using adal windows phone app here.

you grant native client application access azure service management api:

enter image description here


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -