Validate Username and Password, REST API 6.1

Validate Username and Password, REST API 6.1

This question is not answered

I am trying to validate a username and password using this documentation for the REST API in Telligent Evolution 6.1.

The UploadData call (see above link) throws a "(500) Internal Server Error" for any username and password combo.

Here is the code I am using; it is almost identical to the above link:

var webClient = new WebClient();
string adminKey = String.Format("{0}:{1}""mykey""my username");
string adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));
webClient.Headers.Add("Rest-User-Token", adminKeyBase64);
webClient.Headers.Add("Content-Type""application/x-www-form-urlencoded");

string requestUrl = "http://myactualsite.com/api.ashx/v2/users/validate.json";
string data = "?Username=" + username + "&Password=" + password;

webClient.UploadData(requestUrl, "POST"Encoding.ASCII.GetBytes(data));

Also, what is actually returned by UploadData? I'm guessing its the JSON/XML response as a byte array, but the documentation doesn't make any reference to setting this byte array to a variable for later use. 

Thanks for any help.

All Replies
  • Check the error element of the response.  That should provide more details.
     
    Looking at your request, I suspect the problem is with your data.  You shouldn’t have that ? at the beginning of the data string.  Also you are not encoding the username or password properly.
     
    Alex Crome
    Support Developer
    o: + 44 203 178 3010
    telligent.com
     
    From: kevin.h [mailto:bounce-kevinh@communities.telligent.com]
    Sent: 16 July 2012 16:29
    To: discussion_evolution@communities.telligent.com
    Subject: [Telligent Evolution Platform Discussion] Validate Username and Password, REST API 6.1
     

    I am trying to validate a username and password using this documentation for the REST API in Telligent Evolution 6.1.

    The UploadData call (see above link) throws a "(500) Internal Server Error" for any username and password combo.

    Here is the code I am using; it is almost identical to the above link:

    var webClient = new WebClient(); string adminKey = String.Format("{0}:{1}", "mykey", "my username"); string adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey)); webClient.Headers.Add("Rest-User-Token", adminKeyBase64); webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");  string requestUrl = "http://myactualsite.com/api.ashx/v2/users/validate.json"; string data = "?Username=" + username + "&Password=" + password;  webClient.UploadData(requestUrl, "POST", Encoding.ASCII.GetBytes(data));

    Also, what is actually returned by UploadData? I'm guessing its the JSON/XML response as a byte array, but the documentation doesn't make any reference to setting this byte array to a variable for later use. 

    Thanks for any help.

  • "Also you are not encoding the username or password properly" Could you specify what the proper encoding is?

  • You need to encode per the application/x-www-form-urlencoded content type you're submitting data as - see www.w3.org/.../forms.html for more details.

    I'd recommend you instead use the UploadValues method on the web client to make your REST request.  This takes in a NameValueCollection as input for your data and handles the encoding for you.  Below is a powershell script example, which can be easily translated to c#  Finally, you should make sure you perform this operation over an SSL connection, otherwise you'll be submitting passwords in plain text.

    #Configuration
    $Url = "https://test.com/"
    $Username = "admin"
    $ApiKey = "dddd"
    #End Configuration
    
    $UserToken =[Convert]::ToBase64String([System.Text.Encoding]::Utf8.GetBytes("${ApiKey}:${Username}"))
    $WebClient = new-object System.Net.WebClient
    $WebClient.Headers.Add("Rest-User-Token", $UserToken)
    
    $data = new-object System.Collections.Specialized.NameValueCollection
    $data["Username"] = "admin"
    $data["Password"] = "password"
    
    $WebClient.Headers.Add("Rest-Method", "PUT")
    $WebClient.UploadValues("$Url/api.ashx/v2/users/validate.xml", $data) | out-null 
    
  • I implemented this with UploadValues and a NameValueCollection and I get the following response back (formatted in HTML):

    Sorry, there was a problem with your last request! Either the site is offline or an unhandled error occurred. We apologize and have logged the error. Please try your request again or if you know who your site administrator is let them know too.

    I'm thinking this might be a permissions issue. Do I need the permission "Site - Impersonate Users" mentioned here? Or maybe the  "Site - Manage Membership" permission mentioned in this 5.x documentation?

  • For that error, look in your server event logs / exception reports and you should bet back the full stack trace for the error.

    And yes, you do need the Site - Manage Membership permission to validate passwords against the RESt API.

  • Alex, I used the code you provided above. The request goes through successfully, no issues with permissions, but returns a generic error "Sorry, there was a problem with your last request!" In the site log, it shows:

    User Agent:

    Path: /api.ashx/v2/users/validate.xml as HTTP POST

    Referrer:

    Message: Object reference not set to an instance of an object.

    System.NullReferenceException: Object reference not set to an instance of an object.

    at Telligent.Evolution.Rest.Resources.Users.UserController.Update(UserUpdateRequest request)

    Any suggestions?

  • Are you using Single Sign on?  If so you cannot use the validate endpoint as Telligent has no knowledge of your user credentials.  You need to validate directly against your SSO system.