Table of contents
No headers

Perform a call to POST: users/authenticate with an apikey to force user creation of a local user and retrieve the authentication token for the user.

string DEKIAPIURL = "http://host/@api/deki/";
string APIKEY = "apikey";
string LOGIN_USER = "Joe";

string authtoken = string.Empty;

UriBuilder ub = new UriBuilder(DEKIAPIURL);
ub.Path += "users/authenticate";
ub.Query += string.Format("&apikey={0}", APIKEY);
ub.Query += string.Format("&authprovider={0}", 1);

HttpWebRequest authTokenRequest = (HttpWebRequest) HttpWebRequest.Create(ub.Uri);
authTokenRequest.Credentials = new NetworkCredential(LOGIN_USER, string.Empty);
authTokenRequest.PreAuthenticate = true;
authTokenRequest.ContentLength = 0;
authTokenRequest.Method = "POST";

HttpWebResponse rsp = null;
try {
    rsp = (HttpWebResponse) authTokenRequest.GetResponse();

    if (rsp.StatusCode == HttpStatusCode.OK) {
        authtoken = new System.IO.StreamReader(rsp.GetResponseStream()).ReadToEnd();
    }
} catch (WebException x) {
    Console.WriteLine(new System.IO.StreamReader(x.Response.GetResponseStream()).ReadToEnd());
} finally {
    if (rsp != null) {
        rsp.Close();
    }
}

 

Same as above but with Dream's Plug helper class.

string DEKIAPIURL = "http://host/@api/deki/";
string APIKEY = "apikey";
string LOGIN_USER = "moe";
string authtoken = Plug.New(DEKIAPIURL)
    .At("users", "authenticate")
    .With("apikey", APIKEY)
    .with("authprovider", 1)
    .WithCredentials(LOGIN_USER, string.Empty)
    .Post()
    .AsText();

 

Same as above but with command line curl. (note, you'll need to escape the quotes and &'s with \)

curl -X POST -d "" "http://moe@host/@api/deki/users/authenticate?authprovider=1&apikey=myapikey
Tag page
You must login to post a comment.