OAuth 2.0 authentication in RestSharp -


i trying authenticate restful service (sabre rest api) using restsharp library not able authenticate it. using client id , secret. please tell me how authenticate using oauth 2.0 authenticator.

i have tried code. ( sabre using oauth 2.0 authentication )

public actionresult index() {     var client = new restclient("https://api.test.sabre.com");     client.authenticator = new httpbasicauthenticator("myclientid", "myclientsecret");      restrequest request = new restrequest("/v1/auth/token", method.post);     request.addheader("authorization", "basic " + client);     request.addheader("content-type", "application/x-www-form-urlencoded");     request.addparameter("grant_type", "client_credentials");      irestresponse response = client.execute(request);     var content = response.content;     viewbag.r = content;     return view(); } 

i got result

{"error":"invalid_client","error_description":"credentials missing or syntax not correct"} 

please tell doing wrong. thanks

snapshot of fiddler comparison of running code (not restsharp) , code using restsharp shown

with restsharp

using restsharp not using restsharp

seems me adding authorization header twice. documentation here says

the authenticator’s authenticate method first thing called upon calling restclient.execute

looking @ implementation of httpbasicauthenticator, authenticate method adds appropriate header request.

so remove following line example:

request.addheader("authorization", "basic " + client);


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -