Forum Discussion
authentication issue when embedding in aspnetcore
- 8 years ago
endpoints have changed:
AuthorityUrl = "https://login.windows.net/common/oauth2/token/
in one of the examples it was
AuthorityUrl = "https://login.windows.net/common/oauth2/authorize/
which is what i had in my code
hope this helps
hey michael
thx for the response
but if you read my orig post
i stated i had already followed that post
and the result im getting is the result i posted
(adjusted so as to render the non-json result i am getting)
for clarity here is my current code:
public async Task<ActionResult> index() {
var result = new EmbedConfig { Username = Username };
var error = GetWebConfigErrors();
if (error != null)
{
result.ErrorMessage = error;
return View(result);
}
var authenticationResult = await AuthenticateAsync();
if (authenticationResult == null) {
result.ErrorMessage = "Authentication Failed.";
return View(result);
}
else
{
return View(new connectVM(
isJson(authenticationResult) ? JsonConvert.DeserializeObject<string>(authenticationResult) : authenticationResult));
}
//var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");
}
//.private static async Task<OAuthResult> AuthenticateAsync()
// JsonConvert.DeserializeObject<OAuthResult>(authenticationResult)
private static async Task<string> AuthenticateAsync()
{
Uri oauthEndpoint = new Uri(AuthorityUrl);
using (HttpClient client = new HttpClient())
{
HttpResponseMessage result = await client.PostAsync(oauthEndpoint, new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("resource", ResourceUrl),
new KeyValuePair<string, string>("client_id", ClientId),
new KeyValuePair<string, string>("grant_type", "password"),
new KeyValuePair<string, string>("username", Username),
new KeyValuePair<string, string>("password", Password),
new KeyValuePair<string, string>("scope", "openid"),
}));
string content = await result.Content.ReadAsStringAsync();
//Console.WriteLine(content.ToString());
return content.ToString();
}
}
UPDATE:
ive tried logging in directly through browser url
here is the url im using:
does the url at least look correct for the non-sensitive info?
still getting the sign in box
I'm having the exactly same issue, with the same code. Have also tried to get the token using Postman.
Always getting the Sign in page as response.
Here is the request:
POST /common/oauth2/authorize/ HTTP/1.1 Host: login.windows.net Content-Type: application/x-www-form-urlencoded Cache-Control: no-cache client_id=clientId& resource=https%3A%2F%2Fanalysis.windows.net%2Fpowerbi%2Fapi& grant_type=password& username=user@domain& password=userpassword& scope=openid
- toy8 years agoAdvocate I
endpoints have changed:
AuthorityUrl = "https://login.windows.net/common/oauth2/token/
in one of the examples it was
AuthorityUrl = "https://login.windows.net/common/oauth2/authorize/
which is what i had in my code
hope this helps
- Ameb8 years agoHelper IThank you! Was the endpoint :)