What is the proper way to authenticate requests to consume t

Posted by Community Admin on 04-Aug-2018 16:10

What is the proper way to authenticate requests to consume the WCF services?

All Replies

Posted by Community Admin on 07-Mar-2014 00:00

I have seen many questions and posts about this, but none provide definitive/working answers.  I am using Sitefinity 6.3 and specifically trying to use the /sitefinity/Services/Security/Users.svc/ WCF service through a Console Application, using the Restsharp library.  There must be some working code somewhere!

Thanks,

Dave

Posted by Community Admin on 12-Mar-2014 00:00

This is the code I ended up using:

 

public bool Authenticate(string username, string password)
    var url = "Sitefinity/Authenticate/SWT";
 
    var request = new RestRequest(url, Method.POST);
 
    request.AddParameter("wrap_name", username);
    request.AddParameter("wrap_password", password);
 
    request.AddParameter("Content-Type", "application/x-www-form-urlencoded");
 
    var response = this.client.Execute(request);
 
    if (response.StatusCode == System.Net.HttpStatusCode.OK)
    
        var parameters = HttpUtility.ParseQueryString(response.Content);
 
        this.token = parameters["wrap_access_token"];
 
         
        return !String.IsNullOrEmpty(this.token);
    
 
    return false;

 

Then whenever you make an actual API request, include this header: 

request.AddHeader("Authorization", "WRAP access_token=\"" + this.token + "\"");

This thread is closed