[英]how to signin using oauth2 authorization Code Grant flow in UWP Desktop app
I am trying to enable single sigon in my UWP app.我正在尝试在我的 UWP 应用程序中启用单 sigon。
I tried using WebAuthenticationBroker and able to get the AuthCode我尝试使用 WebAuthenticationBroker 并能够获取 AuthCode
var authenticationResult = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, requestUri, redirectUri);
The above code returns me the authorization code which i can use to exchange for access token when i make another call but it always gives me bad request error.上面的代码返回给我授权码,当我再次调用时,我可以用它来交换访问令牌,但它总是给我错误的请求错误。 For the access token call i am using regular httpclient library对于访问令牌调用,我使用的是常规 httpclient 库
JObject jsonObject = new JObject();
jsonObject["code"] = autorizationCode;
jsonObject["grant_type"] = "authorization_code";
jsonObject["redirect_uri"] = redirectUri.AbsoluteUri;
var json = jsonObject.ToString();
HttpStringContent requestBody = new HttpStringContent(json, UnicodeEncoding.Utf8, "application/json");
var httpResponseMessage = await client.PostAsync(new Uri("https://<my app url>.com/oauth2/token"), requestBody);
I tried from postman and i get the same error too.我从 postman 尝试过,我也得到了同样的错误。
Is that possible to get access token with 0auth2.0 authorization grant flow in windows desktop apps based on UWP platform?是否可以在基于 UWP 平台的 windows 桌面应用程序中获得具有 0auth2.0 授权授予流程的访问令牌? Does it expect the request to come from the actual host uri in case of fetching access token in exchange of authorization code?在获取访问令牌以交换授权码的情况下,它是否期望请求来自实际的主机 uri?
Some of the parameters needs to be sent as encoded and having below code solved the issue一些参数需要作为编码发送,下面的代码解决了这个问题
List<KeyValuePair<string, string>> postData = new List<KeyValuePair<string, string>>();
postData.Add(new KeyValuePair<string, string>("code", autorizationCode));
var encodedReqBody = new FormUrlEncodedContent(postData)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.