//gavdcodeend 03 //gavdcodebegin 04 static void CreateChannelApp() { string graphQuery = "https://graph.microsoft.com/v1.0/teams/" + "5b409eec-a4ae-4f04-a354-0434c444265d/channels"; AdAppToken adToken = GetAzureTokenApplication(); //AdAppToken adToken = GetAzureTokenDelegation(); string myBody = "{ " + "\"displayName\": \"Graph Channel 20\"," + "\"description\": \"Channel created with Graph\"" + " }"; RestClient myClient = new RestClient(); RestRequest myRequest = new RestRequest(graphQuery, Method.POST); myRequest.AddHeader("Authorization", adToken.token_type + " " + adToken.access_token); myRequest.AddHeader("ContentType", "application/json"); myRequest.AddJsonBody(myBody); string resultText = myClient.Execute(myRequest).Content; Console.WriteLine(resultText); }
//gavdcodeend 01 //gavdcodebegin 07 static AdAppToken GetAzureTokenDelegation() { string LoginUrl = "https://login.microsoftonline.com"; string ScopeUrl = "https://graph.microsoft.com/.default"; string myClientID = ConfigurationManager.AppSettings["ClientIdDel"]; string myTenantName = ConfigurationManager.AppSettings["TenantName"]; string myUserName = ConfigurationManager.AppSettings["UserName"]; string myUserPw = ConfigurationManager.AppSettings["UserPw"]; string myUri = LoginUrl + "/" + myTenantName + "/oauth2/v2.0/token"; RestClient myClient = new RestClient(); RestRequest myRequest = new RestRequest(myUri, Method.POST); myRequest.AddHeader("Content-Type", "application/x-www-form-urlencoded"); string myBody = "Scope=" + HttpUtility.UrlEncode(ScopeUrl) + "&" + "grant_type=Password&" + "client_id=" + myClientID + "&" + "Username="******"&" + "Password="******""; myRequest.AddParameter("", myBody, ParameterType.RequestBody); string tokenJSON = myClient.Execute(myRequest).Content; AdAppToken tokenObj = JsonConvert.DeserializeObject <AdAppToken>(tokenJSON); return(tokenObj); }
//gavdcodebegin 03 static void GetTeamApp() { string graphQuery = "https://graph.microsoft.com/v1.0/teams/5b409eec-a4ae-4f04-a354-0434c444265d"; //AdAppToken adToken = GetAzureTokenApplication(); AdAppToken adToken = GetAzureTokenDelegation(); RestClient myClient = new RestClient(); RestRequest myRequest = new RestRequest(graphQuery, Method.GET); myRequest.AddHeader("Authorization", adToken.token_type + " " + adToken.access_token); string resultText = myClient.Execute(myRequest).Content; Console.WriteLine(resultText); }
//gavdcodeend 04 static void GetChannelApp() { string graphQuery = "https://graph.microsoft.com/v1.0/teams/" + "5b409eec-a4ae-4f04-a354-0434c444265d/channels/" + "19:[email protected]"; AdAppToken adToken = GetAzureTokenApplication(); //AdAppToken adToken = GetAzureTokenDelegation(); RestClient myClient = new RestClient(); RestRequest myRequest = new RestRequest(graphQuery, Method.GET); myRequest.AddHeader("Authorization", adToken.token_type + " " + adToken.access_token); string resultText = myClient.Execute(myRequest).Content; Console.WriteLine(resultText); }