+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / What is the proper way to authenticate requests to consume the WCF services?

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

2 posts, 1 answered
  1. Dave
    Dave avatar
    76 posts
    Registered:
    10 Mar 2008
    07 Mar 2014
    Link to this post

    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

  2. Dave
    Dave avatar
    76 posts
    Registered:
    10 Mar 2008
    12 Mar 2014
    Link to this post

    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 + "\"");

    Answered
2 posts, 1 answered