Quantcast
Channel: Azure Active Directory forum
Viewing all articles
Browse latest Browse all 16000

O365 group udpate using Microsoft Graph

$
0
0
Following code is 
List<KeyValuePair<string, string>> vals = new List<KeyValuePair<string, string>>();

                string authString = "https://login.microsoftonline.com/" + tenantName;
                string resource = "https://graph.microsoft.com";

                AuthenticationContext authenticationContext = new AuthenticationContext(authString, false);

                vals.Add(new KeyValuePair<string, string>("client_id", clientId));
                vals.Add(new KeyValuePair<string, string>("resource", resource));
                vals.Add(new KeyValuePair<string, string>("username", userName));
                vals.Add(new KeyValuePair<string, string>("password", password));
                vals.Add(new KeyValuePair<string, string>("grant_type", "client_credentials"));
                vals.Add(new KeyValuePair<string, string>("client_secret", key));

                string url = string.Format("https://login.windows.net/{0}/oauth2/token", tenantName);

                using (HttpClient httpClient = new HttpClient())
                {
                    httpClient.DefaultRequestHeaders.Add("Cache-Control", "no-cache");

                    HttpContent content = new FormUrlEncodedContent(vals);
                    HttpResponseMessage hrm = httpClient.PostAsync(url, content).Result;

                    AuthenticationResponse authenticationResponse = null;
                    if (hrm.IsSuccessStatusCode)
                    {
                        Stream data = await hrm.Content.ReadAsStreamAsync();
                        DataContractJsonSerializer serializer = new
                        DataContractJsonSerializer(typeof(AuthenticationResponse));
                        authenticationResponse = (AuthenticationResponse)serializer.ReadObject(data);

                        var accessToken = authenticationResponse.access_token;

                        var a = UnifiedGroupsUtility.GetUnifiedGroup(groupID, accessToken);
                        // Update description and group logo programatically
                        
                        Stream groupLogoStream1 = new FileStream(@"D:\\sandviklogo.png",
                                    FileMode.Open, FileAccess.Read);

                        UnifiedGroupsUtility.UpdateUnifiedGroup(groupID, accessToken, isPrivate: true,
        owners: ownersList, members: ownersList);

                        UnifiedGroupsUtility.UpdateUnifiedGroup(groupID, accessToken, isPrivate: true, description: "Dddd",
        groupLogo: groupLogoStream1);

                        groupLogoStream1.Close();

                        // Delete group programatically
                        //UnifiedGroupsUtility.DeleteUnifiedGroup(groupId, accessToken);

                    }
                }


Viewing all articles
Browse latest Browse all 16000

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>