我目前正在为 Windows 8 消费者预览版编写一个 C# metro 应用程序,它从我基于 REST 的网络服务中获取一些数据。我希望应用程序使用当前用户的 Windows Live 帐户对服务进行身份验证。因此,我将 Windows Live SDK 添加到我的解决方案中,并将文档中的以下代码片段粘贴到我的登录 View 中:
LiveAuthClient liveClient = new LiveAuthClient();
LiveLoginResult loginResult = await liveClient.Login(new string[] { "wl.signin" });
登录调用成功后,我想通过 SSL 将 LiveConnectSession
的加密 AuthenticationToken
传递到我的网络服务,它应该解密 token 并读取它的信息感兴趣(这就是文档对此类 SSO 场景的建议)。但遗憾的是, session 的 AuthenticationToken
属性始终为 null
。我在这里遗漏了什么吗?
最佳答案
我遇到了同样的问题并意识到我的配置有两个问题:
- 我没有在 https://manage.dev.live.com 的 API 设置中定义“重定向域”
- 我没有使用重载的 LiveAuthClient 构造函数
例如在您指定的 API 设置中:
Redirect domain:
http://localhost/myapp
然后您使用 LiveAuthClient 的构造函数重载:
var authClient = new LiveAuthClient("http://localhost/myapp");
var loginResult = await authClient.LoginAsync("wl-signin");
//this should no longer be null
var authToken = loginResult.Session.AuthenticationToken;
据我所知,重定向 URI 不需要指向工作端点,只要这两个值匹配,您就可以开展业务。
关于c# - AuthenticationToken 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9572779/