【发布时间】:2017-07-05 02:12:53
【问题描述】:
我正在尝试使用 auth0 winform、server、authorization extension 设置从 winform 客户端到 Web api 服务的角色身份验证。
通过 winform,我可以进行身份验证并获取 access_token 及其角色(管理员)
var auth0 = new Auth0Client(
"xxx.au.auth0.com",
"1Zf2W81KYrbHJ8MjPYd...");
var user = auth0.LoginAsync(this);
access_token = user.Result.IdToken
在调用webapi时传递token,可以传递[Authorize]但不能传递[Authorize(Roles=admin)]
var client = new RestClient("http://localhost:61758/api/values");
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", string.Format("Bearer " + access_token));
查看函数JsonWebToken.cs\ValidateToken,我发现payloadData只有几个值,但根本没有roles:
{"iss":"https://xxx.au.auth0.com/","sub":"auth0|57e37cc190da2a82c5d6","aud":"2W81KYrbHJ8MjPYd2WVyVrH3","exp":1487259046,"iat":1487223046}
知道为什么角色会从令牌中消失吗?
【问题讨论】:
标签: c# winforms asp.net-web-api auth0