Here's the context:
I have an external application (let's call it EA) which contain users. Each user is able to login using an email and a password.
I have an Azure Active Directory containg users. They are exactly the same users as in the EA.
Here's the scenario:
Here's the problem:
Here's my ugly fix:
public async Task<string> GetTokenUser(string email, string password)
{
string token = null;
var clientID = "<ApplicationClientID>";
var secret = "<ApplicationSecret>";
var tenantID = HttpUtility.UrlEncode("<TenantDomain>");
var resource = HttpUtility.UrlEncode("https://graph.microsoft.com");
email= HttpUtility.UrlEncode(email);
password= HttpUtility.UrlEncode(password);
using (HttpClient client = new HttpClient())
{
var tokenEndpoint = @"https://login.windows.net/" + tenantID + "/oauth2/token";
var accept = "application/json";
client.DefaultRequestHeaders.Add("Accept", accept);
string postBody = @"resource=" + resource + @"
&client_id=" + clientID + @"
&client_secret=" + secret + @"
&grant_type=password
&username=" + email + @"
&password=" + password + "&scope=openid";
using (var response = await client.PostAsync(tokenEndpoint, new StringContent(postBody, Encoding.UTF8, "application/x-www-form-urlencoded")))
{
if (response.IsSuccessStatusCode)
{
var jsonresult = JObject.Parse(await response.Content.ReadAsStringAsync());
token = (string)jsonresult["access_token"];
}
}
}
return token;
}
Here's what I need:
Important note: I have absolutely no preference on how this could be achieved, as long as it works and it is reliable.
Edit 1: Typo in code
Azure AD authentication is necessary if you want to access Microsoft Graph.
Create onlineMeeting only supports Delegated permission, which means you have to follow Get access on behalf of a user to get the access token.
So if you don't want to use ROPC flow, you need to integrate AAD authorization sign in into your project.
Please follow this document to learn how to do it.