Пример #1
0
        public static async Task <string> GenerateJwtAsync(ClaimsPrincipal principal, IJwtFactory jwtFactory, TokenScheme scheme = TokenScheme.Default, JsonSerializerSettings serializerSettings = null)
        {
            var response = new
            {
                id         = principal.FindFirstValue(ClaimTypes.NameIdentifier),
                auth_token = await jwtFactory.CreateTokenAsync(principal, scheme),
                expires_in = (int)jwtFactory.GetExpiration()
            };

            return(JsonConvert.SerializeObject(response, serializerSettings ?? new JsonSerializerSettings {
                Formatting = Formatting.Indented
            }));
        }
        public async Task <IActionResult> Login([FromBody] Login model)
        {
            if (!await _organizationService.CheckLoginCredentialAsync(model))
            {
                return(AppResponse());
            }
            var accessToken = await _jwtFactory.CreateTokenAsync(model.OrgIdentifier);

            return(AppResponse(new
            {
                access_token = accessToken
            }, "登录成功"));
        }