Exemplo n.º 1
0
        private async Task <ReturnDto> Auth(VerifyEnum authority, AuthorityModel model)
        {
            ReturnDto ret;
            var       authorities = _issuers["owner"].Authorities;
            string    token       = model.token;

            if (string.IsNullOrWhiteSpace(token))
            {
                token = JwtHelper.GenerateToken(new Claim[] { }, 60);
            }

            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);

                    ret = await ResultFactory(authority, verifyResult);

                    return(ret);
                } catch (Exception exc) {
                    ret = ExceptionReturn(exc);
                    return(ret);
                }
            }
            return(TokenNotValid());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OtpLogin(OtpLoginDto otpLoginDto)
        {
            dynamic jsonObject = new JObject();

            jsonObject.otp = otpLoginDto.Otp;

            AuthorityModel model = new AuthorityModel()
            {
                payload = jsonObject,
                token   = otpLoginDto.Token
            };

            return(Ok(await Auth(VerifyEnum.otp, model)));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetOtp(OtpDto otpDto)
        {
            dynamic jsonObject = new JObject();

            jsonObject.phone = otpDto.Phone;

            AuthorityModel model = new AuthorityModel()
            {
                payload = jsonObject,
                token   = ""
            };

            return(Ok(await Auth(VerifyEnum.account, model)));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> OtpResetPassword(OtpUpdatePasswordDto otpUpdatePassword)
        {
            dynamic jsonObject = new JObject();

            jsonObject.otp      = otpUpdatePassword.Otp;
            jsonObject.password = otpUpdatePassword.NewPassword;
            AuthorityModel model = new AuthorityModel()
            {
                payload = jsonObject,
                token   = otpUpdatePassword.Token
            };

            return(Ok(await Auth(VerifyEnum.otp, model)));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> UserPassLogin(UserPassDto userPassDto)
        {
            dynamic jsonObject = new JObject();

            jsonObject.phone    = userPassDto.Phone;
            jsonObject.password = userPassDto.Password;

            AuthorityModel model = new AuthorityModel()
            {
                payload = jsonObject,
                token   = ""
            };

            return(Ok(await Auth(VerifyEnum.login, model)));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> RefreshToken(RefreshTokenDto refreshTokenDto)
        {
            IEnumerable <KeyValuePair <string, string> > keyValuePairs = new Dictionary <string, string> {
                { "grant_type", "refresh_token" }, { "client_id", "Authentication" }, { "client_secret", "clientsecret" }, { "scope", "api.sample offline_access" }, { "refresh_token", refreshTokenDto.RefreshToken }
            };
            var        domin      = ContextHelper.GetDomin();
            AccesToken accesToken = await HttpClientHelper.PostFormUrlEncoded <AccesToken>($"{domin.AbsoluteUri}connect/token", keyValuePairs);

            dynamic jsonObject = new JObject();

            if (!string.IsNullOrWhiteSpace(accesToken.access_token))
            {
                AuthorityModel model = new AuthorityModel()
                {
                    payload = jsonObject,
                    token   = accesToken.access_token
                };
                var resut = await Auth(VerifyEnum.refreshToken, model);

                if (!resut.Status)
                {
                    return(FaildAccessToken());
                }

                accesToken.auth_token = StringCipher.Encrypt(resut.Data.verify_token);

                return(Ok(new ReturnDto()
                {
                    Data = accesToken,
                    ErrorData = null,
                    Status = true
                }));
            }

            return(Ok(new ReturnDto()
            {
                Data = null,
                ErrorData = null,
                Status = false
            }));;
        }