What is the proper way to authenticate requests to consume the WCF services?
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
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 +
"\""
);