WinRT - OAuth2获取访问令牌

时间:2012-10-30 14:01:23

标签: 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%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中传递,它与OAuth2保持联系。

你知道如何获得这些参数吗?

编辑:已解决。它在将“https:// localhost”作为redirect_uri / endUri传递后开始工作。

1 个答案:

答案 0 :(得分:0)

我建议您使用像Hammock这样的库。

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

Flickr可能有关于OAuth流程如何运作的最佳总结说明(有图片!) - http://www.flickr.com/services/api/auth.oauth.html

祝你好运

相关问题