我在后端有以下方法,我想获取通过 live sdk 登录的用户的访问 ID:
public class AccountController : ApiController
{
[HttpGet]
[Route("Account/Authenticate/LiveUser")]
public void AuthenticateLiveUser()
{
//TODO: Inspect the request query to get the access token
}
}
在前端,我有以下代码:
<script type="text/javascript">
WL.init({
client_id: '00000000XXXXXXXX',
redirect_uri: 'http://XXXXXXXXXXXXX.us/Account/Authenticate/LiveUser',
scope: 'wl.signin',
response_type: 'token'
});
WL.ui({
name: "signin",
element: "signin"
});
</script>
我能够在页面上打开实时登录,登录并且实时服务器响应以下消息(从提琴手看到):
HTTP/1.1 302 Found
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 0
Content-Type: text/html; charset=utf-8
Expires: Sat, 18 Oct 2014 19:52:24 GMT
Location: http://XXXXXXXXXXXXX.us/Account/Authenticate/LiveUser#access_token=<<ACCESS_TOKEN>>&token_type=bearer&expires_in=3600&scope=wl.signin%20wl.basic%20wl.emails&state=redirect_type%3dauth%26display%3dpage%26request_ts%3d1413662001911%26response_method%3durl%26secure_cookie%3dfalse&user_id=<<USER_ID>>
Server: Microsoft-IIS/7.5
P3P: CP="DSP CUR OTPi IND OTRi ONL FIN"
注意:上面的重定向将用户转发到正确的地址,它包括访问令牌和用户 ID,在上面的代码中被审查。
但是发送到我的服务器的请求如下,请注意缺少访问令牌和用户 ID
GET http://XXXXXXXXXXXXX.us/Account/Authenticate/LiveUser HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: en-US,en;q=0.8,ja;q=0.6,zh-Hant-HK;q=0.4,zh-Hant;q=0.2
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)
Accept-Encoding: gzip, deflate
Host: nsyncservices.us
DNT: 1
Connection: Keep-Alive
回到原点,我正在调试我的AuthenticateLiveUser
服务处理程序,但没有访问令牌或用户 ID,这将允许我访问实时服务。
我究竟做错了什么?如何获取访问令牌和用户 ID 到我的服务器端代码?