[英]Issue with authenticating to Onedrive using Oauth?
I am trying to authenticate to Onedrive using the OAuth Token flow process.我正在尝试使用 OAuth 令牌流程对 Onedrive 进行身份验证。 So basically the user enters their clientid, client secret and then they are redirected to the Microsoft Login screen to authenticate and receive an access token.所以基本上用户输入他们的客户端 ID、客户端密码,然后他们被重定向到 Microsoft 登录屏幕以进行身份验证并接收访问令牌。 I have done the following:我做了以下工作:
public async Task GetTokenAsync(string tenant, string clientId, string clientSecret)
{
HttpResponseMessage resp;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
var req = new HttpRequestMessage(HttpMethod.Post, $"https://login.microsoftonline.com/{tenant}/oauth2/token/");
req.Content = new FormUrlEncodedContent(new Dictionary<string, string>
{
{"grant_type", "client_credentials"},
{"client_id", clientId},
{"client_secret", clientSecret},
{"resource", "https://graph.microsoft.com"}
});
try
{
resp = await httpClient.SendAsync(req);
string content = await resp.Content.ReadAsStringAsync();
var jsonObj = new JavaScriptSerializer().Deserialize<dynamic>(content);
string token = jsonObj["access_token"];
}
catch (Exception ex)
{
}
The issue is I want the Microsoft login screen to pop up and the user logs in , once they have been authenticated then the access_token can be extracted.问题是我希望弹出 Microsoft 登录屏幕并让用户登录,一旦他们通过身份验证,就可以提取 access_token。 The process above that I am doing doesnt seem to allow that , what am i doing wrong here ?我正在做的上述过程似乎不允许这样做,我在这里做错了什么?
There are a few things I see amiss here.我在这里看到了一些错误。
References:参考:
[1] https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-implicit-grant-flow [1] https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-implicit-grant-flow
[2] https://developer.microsoft.com/en-us/identity/blogs/msal-js-2-0-supports-authorization-code-flow-is-now-generally-available/ [2] https://developer.microsoft.com/en-us/identity/blogs/msal-js-2-0-supports-authorization-code-flow-is-now-generally-available/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.