public static List <AppRole> GetRolesForApplication(string appId)
        {
            const string uriTemplate = "https://graph.microsoft.com/v1.0/applications?$filter=appId eq '{0}'&$select=appRoles&$format=application/json;odata=nometadata";
            string       uri         = string.Format(uriTemplate, appId);

            JwtSecurityToken token = TokenUtilities.GetTokenFromClientCredentials("https://graph.microsoft.com/");

            HttpWebRequest request = WebRequest.CreateHttp(uri);

            request.Method      = "GET";
            request.ContentType = "application/json";
            request.Headers.Add("Authorization", token.RawData);

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                using (Stream responseStream = response.GetResponseStream())
                {
                    using (StreamReader reader = new StreamReader(responseStream, Encoding.UTF8))
                    {
                        string responseJson = reader.ReadToEnd();

                        GraphResults results = JsonConvert.DeserializeObject <GraphResults>(responseJson);
                        return(results.Applications.FirstOrDefault().AppRoles);
                    }
                }
            }
        }
        public static List <AppRoleAssignment> GetAssignedRolesForUser(string userName, string enterpiseAppId)
        {
            const string uriTemplate = "https://graph.microsoft.com/beta/users/{0}/appRoleAssignments?filter=resourceId eq {1}&format=application/json;odata=nometadata";
            string       uri         = string.Format(uriTemplate, userName, enterpiseAppId);

            JwtSecurityToken token = TokenUtilities.GetTokenFromClientCredentials("https://graph.microsoft.com/");

            HttpWebRequest request = WebRequest.CreateHttp(uri);

            request.Method      = "GET";
            request.ContentType = "application/json";
            request.Headers.Add("Authorization", token.RawData);

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                using (Stream responseStream = response.GetResponseStream())
                {
                    using (StreamReader reader = new StreamReader(responseStream, Encoding.UTF8))
                    {
                        string responseJson = reader.ReadToEnd();

                        GraphResults results = JsonConvert.DeserializeObject <GraphResults>(responseJson);
                        return(results.AppRoleAssignments);
                    }
                }
            }
        }