public async Task updateAuthClientRole(string authUserID, string authRoleID)
        {
            RestClient      userRestClient = new RestClient(endpoint + "users/" + authUserID + "/roles");
            RestRequest     userRequest    = new RestRequest(Method.POST);
            Auth0TokenModel token          = await getTokenModel();

            Auth0AddRoleIDModel responseModel = new Auth0AddRoleIDModel()
            {
                roles = new List <string>()
            };

            responseModel.roles.Add(authRoleID);

            userRequest.AddHeader("authorization", "Bearer " + token.access_token);
            userRequest.AddJsonBody(responseModel);
            IRestResponse response = await userRestClient.ExecuteAsync(userRequest);

            if (response.IsSuccessful)
            {
                return;
            }
            else
            {
                throw new Exception();
            }
        }
        public async Task <Auth0UserInfoModel> getAuthClientByEmail(string authUserEmail)
        {
            RestClient      userRestClient = new RestClient(endpoint + "users-by-email?email=" + authUserEmail);
            RestRequest     userRequest    = new RestRequest(Method.GET);
            Auth0TokenModel token          = await getTokenModel();

            userRequest.AddHeader("authorization", "Bearer " + token.access_token);
            IRestResponse response = await userRestClient.ExecuteAsync(userRequest);

            List <Auth0UserInfoModel> users = JsonConvert.DeserializeObject <List <Auth0UserInfoModel> >(response.Content);

            return(users.First(c => c.email == authUserEmail));
        }
        public async Task <Auth0RoleModel> getAuthRole(string authRoleID)
        {
            RestClient      roleRestClient = new RestClient(endpoint + "roles/" + authRoleID);
            RestRequest     roleRequest    = new RestRequest(Method.GET);
            Auth0TokenModel token          = await getTokenModel();

            roleRequest.AddHeader("authorization", "Bearer " + token.access_token);
            IRestResponse response = await roleRestClient.ExecuteAsync(roleRequest);

            Auth0RoleModel role = JsonConvert.DeserializeObject <Auth0RoleModel>(response.Content);

            return(role);
        }
        public async Task <Auth0UserInfoModel> getAuthClientByID(string authUserID)
        {
            RestClient      userRestClient = new RestClient(endpoint + "users/" + authUserID);
            RestRequest     userRequest    = new RestRequest(Method.GET);
            Auth0TokenModel token          = await getTokenModel();

            userRequest.AddHeader("authorization", "Bearer " + token.access_token);
            IRestResponse response = await userRestClient.ExecuteAsync(userRequest);

            Auth0UserInfoModel user = JsonConvert.DeserializeObject <Auth0UserInfoModel>(response.Content);

            return(user);
        }
        public async Task <Auth0TokenModel> getTokenModel()
        {
            string authClientID       = ConfigRoot["Auth0API:client_id"];
            string authClientSecret   = ConfigRoot["Auth0API:Auth0Client_secret"];
            string authClientAudience = ConfigRoot["Auth0API:authServiceAudience"];
            string tokenURIPath       = ConfigRoot["Auth0API:tokenURIPath"];

            RestClient  tokenRestClient = new RestClient(tokenURIPath);
            RestRequest tokenRequest    = new RestRequest(Method.POST);

            tokenRequest.AddHeader("content-type", "application/json");
            tokenRequest.AddParameter("application/json", "{\"client_id\":\"" + authClientID + "\",\"client_secret\":\"" + authClientSecret + "\",\"audience\":\"" + authClientAudience + "\",\"grant_type\":\"client_credentials\"}", ParameterType.RequestBody);
            IRestResponse tokenResponse = await tokenRestClient.ExecuteAsync(tokenRequest);

            Auth0TokenModel token = JsonConvert.DeserializeObject <Auth0TokenModel>(tokenResponse.Content);

            return(token);
        }
        public async Task deleteAuthClient(string authUserID)
        {
            RestClient      userRestClient = new RestClient(endpoint + "users/" + authUserID);
            RestRequest     userRequest    = new RestRequest(Method.DELETE);
            Auth0TokenModel token          = await getTokenModel();

            userRequest.AddHeader("authorization", "Bearer " + token.access_token);
            IRestResponse response = await userRestClient.ExecuteAsync(userRequest);

            if (response.IsSuccessful)
            {
                return;
            }
            else
            {
                throw new Exception();
            }
        }
        public async Task <Auth0TicketResponse> getPasswordChangeTicketByAuthClientEmail(string authClientEmail)
        {
            RestClient      roleRestClient = new RestClient(endpoint + "tickets/password-change");
            RestRequest     roleRequest    = new RestRequest(Method.POST);
            Auth0TokenModel token          = await getTokenModel();

            roleRequest.AddHeader("authorization", "Bearer " + token.access_token);
            roleRequest.AddJsonBody(new Auth0ChangePasswordModel()
            {
                email                  = authClientEmail,
                connection_id          = ConfigRoot["Auth0API:ConnectionID"],
                mark_email_as_verified = true,
                includeEmailInRedirect = true
            });
            IRestResponse response = await roleRestClient.ExecuteAsync(roleRequest);

            Auth0TicketResponse ticket = JsonConvert.DeserializeObject <Auth0TicketResponse>(response.Content);

            return(ticket);
        }
        public async Task <Auth0UserInfoModel> createAuthClient(string authEmail, string authName)
        {
            RestClient      userRestClient = new RestClient(endpoint + "users");
            RestRequest     userRequest    = new RestRequest(Method.POST);
            Auth0TokenModel token          = await getTokenModel();

            userRequest.AddHeader("authorization", "Bearer " + token.access_token);
            Auth0NewUserModel newUser = new Auth0NewUserModel()
            {
                email        = authEmail,
                name         = authName,
                connection   = "Username-Password-Authentication",
                password     = generateTempPassword(),
                verify_email = false
            };

            userRequest.AddJsonBody(newUser);
            IRestResponse response = await userRestClient.ExecuteAsync(userRequest);

            Auth0UserInfoModel user = JsonConvert.DeserializeObject <Auth0UserInfoModel>(response.Content);

            return(user);
        }
        public async Task updateAuthClientName(string authUserID, string newName)
        {
            RestClient      userRestClient = new RestClient(endpoint + "users/" + authUserID);
            RestRequest     userRequest    = new RestRequest(Method.PATCH);
            Auth0TokenModel token          = await getTokenModel();

            var responseModel = new Models.Auth0_Response_Models.Auth0ChangeNameModel()
            {
                name = newName,
            };

            userRequest.AddHeader("authorization", "Bearer " + token.access_token);
            userRequest.AddJsonBody(responseModel);
            IRestResponse response = await userRestClient.ExecuteAsync(userRequest);

            if (response.IsSuccessful)
            {
                return;
            }
            else
            {
                throw new Exception();
            }
        }