public AdAppToken GetAzureTokenDelegation() { string LoginUrl = "https://login.microsoftonline.com"; string ScopeUrl = "https://graph.microsoft.com/.default"; string myUri = LoginUrl + "/" + TenantName + "/oauth2/v2.0/token"; string myBody = "Scope=" + HttpUtility.UrlEncode(ScopeUrl) + "&" + "grant_type=Password&" + "client_id=" + ClientID + "&" + "Username="******"&" + "Password="******""; RestGraphClient myClient = new RestGraphClient { EndPoint = myUri, Method = HttpVerb.POST, ContentType = "application/x-www-form-urlencoded", PostData = myBody }; Tuple <string, string> tokenJSON = myClient.SendGraphRequestInternal(); if (tokenJSON.Item1.Contains("Error") == false) { AdAppToken tokenObj = JsonConvert.DeserializeObject <AdAppToken>(tokenJSON.Item2); return(tokenObj); } return(null); }
public Tuple <string, string> SendGraphRequest() { AdAppToken adToken = new AdAppToken(); if (Registration == TypeRegistration.Application) { adToken = GetAzureTokenApplication(); } else if (Registration == TypeRegistration.Delegation) { adToken = GetAzureTokenDelegation(); } if (adToken != null) { List <HeaderConfig> myHeadersList = new List <HeaderConfig>(); HeaderConfig authorizationHeader = new HeaderConfig { HeaderTitle = "Authorization", HeaderValue = adToken.token_type + " " + adToken.access_token }; myHeadersList.Add(authorizationHeader); Headers = myHeadersList; return(SendGraphRequestInternal()); } else { Tuple <string, string> tplReturn = new Tuple <string, string> ("Error", string.Empty); return(tplReturn); } }
//gavdcodeend 10 //gavdcodebegin 11 static AdAppToken GetADTokenApplication() { RestGraphClient myClient = new RestGraphClient { ClientID = ConfigurationManager.AppSettings["ClientIdApp"], ClientSecret = ConfigurationManager.AppSettings["ClientSecretApp"], TenantName = ConfigurationManager.AppSettings["TenantName"] }; AdAppToken resultToken = myClient.GetAzureTokenApplication(); return(resultToken); }
//gavdcodeend 11 //gavdcodebegin 12 static AdAppToken GetADTokenDelegation() { RestGraphClient myClient = new RestGraphClient { ClientID = ConfigurationManager.AppSettings["ClientIdDel"], TenantName = ConfigurationManager.AppSettings["TenantName"], UserName = ConfigurationManager.AppSettings["UserName"], UserPw = ConfigurationManager.AppSettings["UserPw"] }; AdAppToken resultToken = myClient.GetAzureTokenDelegation(); return(resultToken); }