Exemplo n.º 1
0
        public AssignRolesToUserOutput AssignRolesToUser(AssignRolesToUserInput input)
        {
            try
            {
                RestHTTP    http = new RestHTTP();
                RestRequest req  = new RestRequest("api/accounts/assignRolesToUser", RestSharp.Method.POST);
                req.AddHeader("Content-Type", "application/json");
                req.AddHeader("Authorization", "Bearer " + input.AccessToken);
                req.AddJsonBody(input);


                var response = http.HttpPost <object>(req);

                AssignRolesToUserOutput output = new AssignRolesToUserOutput();
                output.Id = JsonConvert.DeserializeObject <string>(response.ToString());

                return(output);
            }
            catch (Exception ex)
            {
                WriteLogFile.Append("AssignRolesToUser : ");
                WriteLogFile.Append(ex.Message);
                WriteLogFile.Append(ex.StackTrace);
            }
            return(null);
        }
Exemplo n.º 2
0
        public GetAllUsersOutput GetAllUsers(GetAllUsersInput input)
        {
            try
            {
                RestHTTP    http = new RestHTTP();
                RestRequest req  = null;
                req = new RestRequest("api/accounts/users", RestSharp.Method.POST);

                req.AddHeader("Authorization", "Bearer " + input.AccessToken);
                req.RequestFormat = DataFormat.Json;
                RestSharp.RestClient client = new RestSharp.RestClient(WebConfigurationManager.AppSettings["AuthServerAPI"]);
                var response = client.Execute <GetAllUsersOutput>(req);

                GetAllUsersOutput output = new GetAllUsersOutput();
                output.Users = JsonConvert.DeserializeObject <List <GetUserInfoModel> >(response.Content, new ClaimConverter());

                return(output);
            }
            catch (Exception ex)
            {
                WriteLogFile.Append("GetAllUsers : ");
                WriteLogFile.Append(ex.Message);
                WriteLogFile.Append(ex.StackTrace);
                return(default(GetAllUsersOutput));
            }
        }
Exemplo n.º 3
0
        public UpdateUserInfoOutput UpdateUserInfo(UpdateUserInfoInput input)
        {
            try
            {
                RestHTTP    http = new RestHTTP();
                RestRequest req  = null;
                if (!string.IsNullOrEmpty(input.Id))
                {
                    req = new RestRequest("api/accounts/update", RestSharp.Method.POST);
                }

                req.AddHeader("Authorization", "Bearer " + input.AccessToken);
                req.RequestFormat = DataFormat.Json;
                req.AddJsonBody(input);

                var response = http.HttpPost <UpdateUserInfoOutput>(req);

                return(response);
            }
            catch (Exception ex)
            {
                WriteLogFile.Append("UpdateUserInfo : ");
                WriteLogFile.Append(ex.Message);
                WriteLogFile.Append(ex.StackTrace);
                return(default(UpdateUserInfoOutput));
            }
        }
        public async Task <IHttpActionResult> GetAccessTokenByUserName(GetAccessTokenByUserNameInput input)
        {
            RestHTTP http = new RestHTTP();

            RestSharp.RestRequest req = new RestSharp.RestRequest("/oauth/token", RestSharp.Method.POST);
            input.grant_type = "password";
            req.AddObject(input);

            GetAccessTokenByUserNameOutput output = http.HttpPost <GetAccessTokenByUserNameOutput>(req);

            if (output != null && !string.IsNullOrEmpty(output.AccessToken))
            {
                var user = await this.AppUserManager.FindByNameAsync(input.username);

                if (user != null)
                {
                    output.CurrentUserID     = user.Id;
                    output.TwoFactorAuthFlag = user.TwoFactorEnabled;
                    UserReturnModel userSession = this.TheModelFactory.Create(user);
                    output.UserSession = new UserReturnModel();
                    output.UserSession = userSession;
                }
            }

            return(Ok(output));
        }
Exemplo n.º 5
0
        //Public Methods
        public GetAllRolesOutput GetAllRoles(GetAllRolesInput input)
        {
            try
            {
                RestHTTP    http = new RestHTTP();
                RestRequest req  = new RestRequest("api/roles", RestSharp.Method.POST);
                req.AddHeader("Content-Type", "application/json");
                req.AddHeader("Authorization", "Bearer " + input.AccessToken);
                req.AddJsonBody(input);

                RestSharp.RestClient client = new RestSharp.RestClient(WebConfigurationManager.AppSettings["AuthServerAPI"]);
                var response            = client.Execute <List <RoleModel> >(req);
                List <RoleModel> result = JsonConvert.DeserializeObject <List <RoleModel> >(response.Content);

                GetAllRolesOutput output = new GetAllRolesOutput();
                output.Roles = result;

                return(output);
            }
            catch (Exception ex)
            {
                WriteLogFile.Append("GetAllRoles : ");
                WriteLogFile.Append(ex.Message);
                WriteLogFile.Append(ex.StackTrace);
            }
            return(null);
        }
Exemplo n.º 6
0
        public RegisterExternalOutput RegisterExternal(RegisterExternalInput input)
        {
            RestHTTP http = new RestHTTP();

            RestSharp.RestRequest req = new RestSharp.RestRequest("api/accounts/RegisterExternal", RestSharp.Method.POST);
            req.AddJsonBody(input);

            var response = http.HttpPost <RegisterExternalOutput>(req);

            return(response);
        }
Exemplo n.º 7
0
        public LoginUserOutput LoginUser(LoginUserInput input)
        {
            RestHTTP http = new RestHTTP();

            RestSharp.RestRequest req = new RestSharp.RestRequest("api/accounts/GetAccessTokenByUserName", RestSharp.Method.POST);
            req.AddObject(input);

            RestSharp.RestClient client = new RestSharp.RestClient(WebConfigurationManager.AppSettings["AuthServerAPI"]);
            var             response    = client.Execute <LoginUserOutput>(req);
            LoginUserOutput result      = JsonConvert.DeserializeObject <LoginUserOutput>(response.Content, new ClaimConverter());

            return(result);
        }
Exemplo n.º 8
0
        //Private Methods
        private LoginByLoginTokenOutput LoginByLoginToken(string accessToken)
        {
            var accessTokenObj = _CT.aToken.Deserialize(accessToken);

            LoginByLoginTokenInput Input = new LoginByLoginTokenInput()
            {
                LoginToken = accessTokenObj.AccessToken
            };
            RestHTTP http = new RestHTTP();

            RestSharp.RestRequest req = new RestSharp.RestRequest("api/auth/LoginByLoginToken", RestSharp.Method.POST);
            req.AddObject(Input);

            var response = http.HttpPost <LoginByLoginTokenOutput>(req);

            return(response);
        }
Exemplo n.º 9
0
        //Public Methods
        public RegisterUserOutput RegisterUser(RegisterUserInput input)
        {
            try
            {
                RestHTTP    http = new RestHTTP();
                RestRequest req  = new RestRequest("api/accounts/create", RestSharp.Method.POST);
                req.AddJsonBody(input);
                RegisterUserOutput response = http.HttpPost <RegisterUserOutput>(req);

                return(response);
            }
            catch (Exception ex)
            {
                WriteLogFile.Append("RegisterUser : ");
                WriteLogFile.Append(ex.Message);
                WriteLogFile.Append(ex.StackTrace);
            }
            return(null);
        }
Exemplo n.º 10
0
        public ForgotPasswordOutput ForgotPassword(ForgotPasswordInput input)
        {
            try
            {
                RestHTTP    http = new RestHTTP();
                RestRequest req  = new RestRequest("api/accounts/ForgotPassword", RestSharp.Method.POST);
                req.AddHeader("Content-Type", "application/json");
                req.AddJsonBody(input);
                ForgotPasswordOutput response = http.HttpPost <ForgotPasswordOutput>(req);

                return(response);
            }
            catch (Exception ex)
            {
                WriteLogFile.Append("ForgotPassword : ");
                WriteLogFile.Append(ex.Message);
                WriteLogFile.Append(ex.StackTrace);
            }
            return(null);
        }
Exemplo n.º 11
0
        public ChangePasswordOutput ChangePassword(ChangePasswordInput input)
        {
            try
            {
                RestHTTP    http = new RestHTTP();
                RestRequest req  = new RestRequest("api/accounts/ChangePassword", RestSharp.Method.POST);
                req.AddHeader("Content-Type", "application/json");
                req.AddHeader("Authorization", "Bearer " + input.AccessToken);
                req.AddJsonBody(input);
                ChangePasswordOutput response = http.HttpPost <ChangePasswordOutput>(req);

                return(response);
            }
            catch (Exception ex)
            {
                WriteLogFile.Append("ConfirmPassword : ");
                WriteLogFile.Append(ex.Message);
                WriteLogFile.Append(ex.StackTrace);
            }
            return(null);
        }
Exemplo n.º 12
0
        public DeleteUserOutput DeleteUser(DeleteUserInput input)
        {
            try
            {
                RestHTTP    http = new RestHTTP();
                RestRequest req  = new RestRequest("api/accounts/delete", RestSharp.Method.DELETE);
                req.AddHeader("Content-Type", "application/json");
                req.AddHeader("Authorization", "Bearer " + input.AccessToken);
                req.AddJsonBody(input);
                DeleteUserOutput response = http.HttpPost <DeleteUserOutput>(req);

                return(response);
            }
            catch (Exception ex)
            {
                WriteLogFile.Append("DeleteUser : ");
                WriteLogFile.Append(ex.Message);
                WriteLogFile.Append(ex.StackTrace);
            }
            return(null);
        }
Exemplo n.º 13
0
        public UpdateRoleOutput UpdateRole(UpdateRoleInput input)
        {
            try
            {
                RestHTTP    http = new RestHTTP();
                RestRequest req  = new RestRequest("api/roles/update", RestSharp.Method.POST);
                req.AddHeader("Content-Type", "application/json");
                req.AddHeader("Authorization", "Bearer " + input.AccessToken);
                req.AddJsonBody(input);
                UpdateRoleOutput response = http.HttpPost <UpdateRoleOutput>(req);

                return(response);
            }
            catch (Exception ex)
            {
                WriteLogFile.Append("UpdateRole : ");
                WriteLogFile.Append(ex.Message);
                WriteLogFile.Append(ex.StackTrace);
            }
            return(null);
        }
Exemplo n.º 14
0
        public GetUserSessionByAccessTokenOutput GetUserSessionByAccessToken(string accessToken)
        {
            try
            {
                var handler  = new JwtSecurityTokenHandler();
                var token    = handler.ReadJwtToken(accessToken).Payload.ToList();
                var username = token.Where(a => a.Key == "unique_name").Select(b => b.Value).FirstOrDefault();

                //string username = new System.Collections.Generic.Mscorlib_DictionaryDebugView<string, object>(token.Payload).Items[1].Value;
                //var accessTokenObj = _CT.aToken.Deserialize(accessToken);
                GetUserSessionByAccessTokenInput input = new GetUserSessionByAccessTokenInput();
                input.Username = username.ToString();
                RestHTTP http             = new RestHTTP();
                RestSharp.RestRequest req = new RestSharp.RestRequest("api/accounts/GetUserSessionByAccessToken", RestSharp.Method.POST);
                req.AddHeader("Authorization", "Bearer " + input.AccessToken);
                req.AddObject(input);

                RestSharp.RestClient client = new RestSharp.RestClient(WebConfigurationManager.AppSettings["AuthServerAPI"]);
                var response = client.Execute <GetUserSessionByAccessTokenOutput>(req);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    GetUserSessionByAccessTokenOutput result = JsonConvert.DeserializeObject <GetUserSessionByAccessTokenOutput>(response.Content, new ClaimConverter());
                    result.AccessToken = accessToken;
                    return(result);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }