示例#1
0
        public IActionResult Account(string authority, [FromBody] AuthorityModel model)
        {
            if (model == null || model?.payload == null)
            {
                return(Unauthorized());
            }
            var authorities = _issuers["owner"].Authorities;

            if (!authorities.Any())
            {
                return(Unauthorized());
            }
            string token = model.token;

            if (string.IsNullOrWhiteSpace(authority))
            {
                authority = authorities.Keys.ToArray()[0];
                token     = JwtHelper.GenerateToken(new Claim[] { }, 60);
            }
            if (string.IsNullOrWhiteSpace(token))
            {
                return(Unauthorized());
            }

            var principle = JwtHelper.GetClaimsPrincipal(token);

            if (principle?.Identity?.IsAuthenticated == true)
            {
                try
                {
                    var claimsIdentity = principle.Identity as ClaimsIdentity;
                    var verifyResult   = _issuers["owner"].Verify(authority, claimsIdentity.Claims.ToArray(), model.payload);
                    if (verifyResult.Authority == null)
                    {
                        return(Ok(new { auth_token = verifyResult.Token }));
                    }
                    return(Ok(new { verify_token = verifyResult.Token, authority = verifyResult.Authority, parameters = verifyResult.Payload }));
                }
                catch
                {
                    return(Unauthorized());
                }
            }
            return(Unauthorized());
        }
示例#2
0
 public IActionResult Account([FromBody] AuthorityModel model)
 {
     return(Account("", model));
 }