[英]Azure B2C sign in using Graph API
I am new to Azure and i am working on a WebApi app which can create/delete/update and authenticate a user on Azure AD B2C tenant using Graph API.我是 Azure 的新手,我正在开发一个 WebApi 应用程序,该应用程序可以使用 Graph API 在 Azure AD B2C 租户上创建/删除/更新和验证用户。 I am stuck with the authenticate user on Azure AD B2C.
我坚持使用 Azure AD B2C 上的身份验证用户。 I was successfully able to create user by following code.
我能够通过以下代码成功创建用户。
private async Task<string> CreateUserRequest(string api, string json)
{
AuthenticationResult result = authContext.AcquireToken(Globals.aadGraphResourceId, credential);
HttpClient http = new HttpClient();
string url = Globals.aadGraphEndpoint + tenant + api + "?" + Globals.aadGraphVersion;
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
request.Content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = await http.SendAsync(request);
if (!response.IsSuccessStatusCode)
{
string error = await response.Content.ReadAsStringAsync();
object formatted = JsonConvert.DeserializeObject(error);
throw new WebException("Error Calling the Graph API: \n" + JsonConvert.SerializeObject(formatted, Formatting.Indented));
}
return await response.Content.ReadAsStringAsync();
}
and now i need to use the same way for Authenticate user and get token as the for following code现在我需要对 Authenticate user 使用相同的方式并获取令牌作为以下代码
and now i need to log in/sign in using api call by passing username and password as parameters slimier to above way.现在我需要通过将用户名和密码作为参数传递给上述方式来使用 api 调用登录/登录。
public async Task<string> B2CAuthenticateUser(string userName, string password)
{
return await SendGraphValidateUser("/users/" + userName, null);
}
public async Task<string> SendGraphValidateUser(string api, string query)
{
AuthenticationResult result = authContext.AcquireToken("https://graph.windows.net", credential);
HttpClient http = new HttpClient();
**Here I need your help**
> // string url = "https://graph.windows.net/" + tenant + api + "?" +
> Globals.aadGraphVersion;
> // if (!string.IsNullOrEmpty(query))
> // {
> // url += "&" + query;
> // }
>
>
> //HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
HttpResponseMessage response = await http.SendAsync(request);
if (!response.IsSuccessStatusCode)
{
string error = await response.Content.ReadAsStringAsync();
object formatted = JsonConvert.DeserializeObject(error);
throw new WebException("Error Calling the Graph API: \n" + JsonConvert.SerializeObject(formatted, Formatting.Indented));
}
return await response.Content.ReadAsStringAsync();
}
I hope there should be a way to do this.我希望应该有办法做到这一点。 appreciate if you can suggest a way to do it
如果你能建议一种方法来做到这一点,不胜感激
PS : I have gone through with following related questions and wasn't help much] Authenticate a user on Azure AD B2C using Graph API PS:我已经解决了以下相关问题,但没有多大帮助] 使用 Graph API 对 Azure AD B2C 上的用户进行身份验证
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.