Example #1
0
        public void GetUserRole(string auth0id, string shiftType)
        {
            var       result = Auth0APIClient.GetUserRole(auth0id);
            Auth0Role role   = result.ElementAt(0);

            Assert.AreEqual(role.name, shiftType);
        }
        /// <summary>
        /// Set the role of the chosen user in Auth0
        /// </summary>
        /// <param name="auth0ID"></param>
        /// <param name="shiftType"></param>
        /// <returns></returns>
        public static bool SetRole(string auth0ID, string shiftType)
        {
            try
            {
                if (!ValidateToken())
                {
                    InitAPIToken();
                }

                var client = new RestClient(baseUrl + "users/" + auth0ID + "/roles");
                var req    = new RestRequest(Method.POST);

                Auth0RolesPayload payload = new Auth0RolesPayload();
                Auth0Role         role    = FetchRole(shiftType);
                string[]          roles   = new string[] { role.id };
                payload.roles = roles;
                req.AddJsonBody(payload);

                req.AddHeader("content-type", "application/json");
                req.AddHeader("authorization", "Bearer " + tokenData.access_token);
                var response = client.Execute(req);
                var content  = response.Content;

                return(true);
            }
            catch (Exception e)
            {
                throw new HttpResponseException(Utility.CreateResponseMessage(e));
            }
        }
Example #3
0
        public void FetchRoleTest(string shiftType)
        {
            Auth0Role result = Auth0APIClient.FetchRole(shiftType);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.name, shiftType);
        }