Ejemplo n.º 1
0
        public async Task <ApiDataResponse <AuthSuccesfullModel> > Login([FromBody] RequestLoginModel model)
        {
            //modelState
            var person = PersonDtoToRequestLoginMapper.Instance.MapBack(model);
            var result = await authService.LoginPerson(person);

            if (result.Success)
            {
                return(new ApiDataResponse <AuthSuccesfullModel>(new AuthSuccesfullModel
                {
                    Token = result.Token,
                    RefreshToken = result.RefreshToken
                }));
            }
            else
            {
                var apiErrorResult = AuthResultToApiErrorResponceMapper.Instance.Map(result);
                return(new ApiDataResponse <AuthSuccesfullModel>(200, apiErrorResult));
            }
        }
Ejemplo n.º 2
0
        public async Task CheckPolicy(string email, string password, string resource)
        {
            var authResult = await jwtAuthenticationService.LoginPerson(email, password);

            //if (authResult.Token != null && DateTime.Now < authResult.ExpieryDate)
            //{
            //    //use the existing token
            //}
            //else if (authResult.Token != null && !String.IsNullOrEmpty(authResult.RefreshToken))
            //{
            //    //Get a new access token based on the Refresh Token
            //    token = GetTokens(_clientId, _clientSecret, token.RefreshToken);
            //}
            if (!String.IsNullOrEmpty(authResult.RefreshToken))
            {
                Console.WriteLine(GetSomeResourse(authResult.Token, resource));
            }
            else
            {
                //TODO maybe error view
                Console.WriteLine(authResult.Errors);
            }
        }