C# WinRT-OAuth2获取访问令牌

C# WinRT-OAuth2获取访问令牌,c#,windows-8,windows-runtime,oauth-2.0,windows-store-apps,C#,Windows 8,Windows Runtime,Oauth 2.0,Windows Store Apps,我正在尝试创建一个需要通过OAuth2进行身份验证的Windows应用商店应用程序 首选方式应为WebAuthenticationBroker: const string url = @"https://my.server.srv/mobile-auth/index.pl?" + "client_id=CLIENTID" + "&redirect_uri=https%3A%2F%2F

我正在尝试创建一个需要通过OAuth2进行身份验证的Windows应用商店应用程序

首选方式应为WebAuthenticationBroker:

const string url = @"https://my.server.srv/mobile-auth/index.pl?"
                          + "client_id=CLIENTID"
                           + "&redirect_uri=https%3A%2F%2Fmy.server.srv
                           + "&response_type=code"

Uri startUri = new Uri(url);
Uri endUri = new Uri("https://my.server.srv");

WebAuthenticationResult webAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, startUri, endUri);
if (webAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success)
{
    string token = webAuthenticationResult.ResponseData;
}
但是令牌是空的。应该有服务器响应,即

code=a-secret-code&expires_in=600&token_type=bearer
在GET中传递,GET是OAuth2的编译器

你知道如何获取这些参数吗


编辑:已解决。它在通过之后开始工作。”https://localhost“作为重定向_uri/endUri.

我建议您使用诸如吊床之类的库

通常,对于OAuth2,您首先执行一个请求,以获取将与所有后续请求关联的请求令牌。然后,您可以将该令牌与您的参数一起使用,以执行身份验证请求,该请求将返回您可以操作的响应对象

Flickr可能对OAuth进程的工作原理有最好的概括解释(带图片!):


祝您好运

您是否已验证服务器正在使用其他方法或工具(如Fiddler)返回相应的响应?您能否验证问题是否出在WebAuthenticationBroker上?是的。这段代码(code=a-secret-code…_type=bearer)是在Firefox和Chrome浏览器中通过测试获得的。(我已经隐藏了服务器的名称和访问代码。)我的问题只与WebAuthenticationBroker有关。感谢您的回复。我知道该过程是如何工作的(根据该页面,Flickr似乎使用OAuth 1,而不是OAuth 2)。我找不到一个网站或一个像样的文档哦,吊床或吊床2,所以我不知道它到底是做什么的。但如果它只是一个REST库,对我来说是无用的。我需要在Win Store应用程序中向用户显示登录页面,让他登录并捕获令牌。这正是WebAuthenticationBroker应该做的。