1

我正在尝试创建一个需要通过 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 传递后开始工作。

4

1 回答 1

0

我建议你宁愿使用像 Hammock 这样的库。

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

Flickr 可能有关于 OAuth 过程如何工作的最佳总结解释(带图片!) - http://www.flickr.com/services/api/auth.oauth.html

祝你好运

于 2012-10-31T06:12:25.027 回答