c# - How to secure wcf rest services based on OAuth -


i need secure wcf services based on oauth. in case java application passing me token need validate based on oauth in .net layer , if token passed need call wcf services.

i have checked several examples based on oauth not got idea achieve . please me how achieve based on oauth in .net.

finally solved below implementation

var authheader = weboperationcontext.current.incomingrequest.headers.getvalues("authorization");                 if (authheader == null || authheader.length == 0)                 {                     throw new webfaultexception(httpstatuscode.unauthorized);                 }                 namevaluecollection outgoingquerystring = httputility.parsequerystring(string.empty);                  var parts = authheader[0].split(' ');                 if (parts[0] == "bearer")                 {                     string token = parts[1];                      outgoingquerystring.add("token", token);                     byte[] postdata = encoding.ascii.getbytes(outgoingquerystring.tostring());                      var result = string.empty;                     var httpwebrequest = (httpwebrequest)webrequest.create(oauthconfiguration.setting.checkurl);                     httpwebrequest.contenttype = "application/x-www-form-urlencoded";                     httpwebrequest.method = "post";                     httpwebrequest.headers.add("authorization", getauthorizationheader(oauthconfiguration.setting.clientid, oauthconfiguration.setting.clientsecret));                     httpwebrequest.contentlength = postdata.length;                     using (stream poststream = httpwebrequest.getrequeststream())                     {                         poststream.write(postdata, 0, postdata.length);                         poststream.flush();                         poststream.close();                     }                      var response = (httpwebresponse)httpwebrequest.getresponse();                     var responsestring = new streamreader(response.getresponsestream()).readtoend(); 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -