This fails in postman and in C#
According to the docs I have all the parameters
string content = “{"client_id" : "MX9ts5N0yPyGQhNWFnGi0RRCCMB92nLd", "connection" : "Form217" , "grant_type" : "password" ,"scope" : "openid", "username" : "” + uname + “", "password" : "” + passwd + “"}”;
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, uri);
var uri = “https://railcomm.auth0.com/oauth/ro”;
request.Content = new StringContent(content, System.Text.Encoding.UTF8, “application/json”);
HttpResponseMessage x = await aClient.SendAsync(request);
content =
{“client_id” : “xxxxxxxxxxxxhNWFnGi0RRCCMB92nLd”, “connection” : “Form217” , “grant_type” : “password” ,“scope” : “openid”, “username” : “jsheehan@railcomm.com”, " password" : “xxxxxxxxx”}
Here is a working C# call (using System.Net calls):
HttpClient httpClient = new HttpClient();
var url = "https://tenant.auth0.com/oauth/ro";
var parameters = new Dictionary<string, string>
{
{ "client_id", "CLIENT_ID" },
{ "username", "test@test.com" },
{ "password", "password" },
{ "connection", "Username-Password-Authentication" },
{ "scope", "openid" },
{ "grant_type", "password" }
};
var encodedContent = new FormUrlEncodedContent(parameters);
var response = httpClient.PostAsync(url, encodedContent).Result;
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
// Do something with response. Example get content:
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
}
Unfortunately I can only use System.Net calls.
I am curious why no password is given in this example.How can it authenticate with no password?
Also why not pass application/json and a json formatted string? Its what the documentation shows.
my bad, password is there
This code fails with log below. Someone must have done this with standard C# before.
var uri = “https://railcomm.auth0.com/oauth/ro”;
Uri theUri = new Uri(uri);
string content = "client_id=xxxxxxxxxxxxxQhNWFnGi0RRCCMB92nLd&connection=Form217,grant_type=password,scope=openid,username=jsheehan%railcomm.com,password=" + passwd + "\"";
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, uri);
request.Content = new StringContent(content, System.Text.Encoding.UTF8, "application/x-www-form-urlencoded");
HttpResponseMessage x = await aClient.SendAsync(request);
success = x.IsSuccessStatusCode.ToString();
{
“date”: “2017-04-05T10:59:44.067Z”,
“type”: “f”,
“description”: “missing username parameter”,
“connection_id”: “”,
“ip”: “66.249.79.107”,
“user_agent”: “Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)”,
“details”: {
“error”: {
“message”: “missing username parameter”,
“oauthError”: “missing username parameter”,
“type”: “invalid_request”
},
“body”: {},
“qs”: {
“client_id”: “xxxxxxxxxxxxxPyGQhNWFnGi0RRCCMB92nLd”,
“username”: “jsheehan@railcomm.com”,
“password”: “*****”
}
Please see my original answer (I have edited it to use only System.Net calls). Also, if you have any questions or updates, please comment within this post rather than creating a new post.
This looks great, I will try in in 1 hour, thanks for all your efforts
Prashant,
No Luck. This is my routine, it crashes on PostAsync. The user name and password are set to the logoon credentials I use for http://railcomm/auth0.com
string retval = “”;
var url = “https://railcomm.auth0.com/oauth/ro”;
HttpClient httpClient = new HttpClient();
var parameters = new Dictionary<string, string>
{
{ "client_id", "xxxxxxxxxQhNWFnGi0RRCCMB92nLd" },
{ "username", "jsheehan@railcomm.com" },
{ "password", "xxxxxxxxx" },
{ "connection", "Username-Password-Authentication" },
{ "scope", "openid" },
{ "grant_type", "password" }
};
var encodedContent = new FormUrlEncodedContent(parameters);
var response = httpClient.PostAsync(url, encodedContent).Result;
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
// Do something with response. Example get content:
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
retval = response.StatusCode.ToString();
}//logon
return retval
John
BTW, its statuscode = 401 Unauthorized
When I run the following in Postman I get the error at the end.
I pass my own logon credentials … what is it looking for ?
https://railcomm.auth0.com/oauth/ro
{
“client_id”: “xxxxxxxxxyGQhNWFnGi0RRCCMB92nLd”,
“username”: “jsheehan@railcomm.com”,
“password”: “xxxxxxxxx”,
“connection” : “Username-Password-Authentication”,
“grant_type” : “password”,
“scope”: “openid”
}
{
“error”: “invalid_user_password”,
“error_description”: “Wrong email or password.”
}
got it, username is not an email address, both my code and your sample use email addresses
thanks Prashant