Connect to Azure AD in Azure Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Microsoft.Azure.WebJobs; | |
using Microsoft.Azure.WebJobs.Host; | |
using System.Collections.Generic; | |
using Newtonsoft.Json; | |
using Microsoft.Azure.WebJobs.Extensions.Http; | |
using System.Threading.Tasks; | |
using Microsoft.IdentityModel.Clients.ActiveDirectory; | |
using Microsoft.Extensions.Logging; | |
string TenantID = <TenantID>; | |
string authString = "https://login.windows.net/" + TenantID; | |
string SPServiceUrl = "https://manage.office.com/api/v1.0/" + TenantID + "/activity/feed/subscriptions/content"; | |
string resourceId = "https://manage.office.com"; | |
string clientId = <Client App Id>; | |
string clientSecret = <Client App secret>; | |
var authenticationContext = new AuthenticationContext(authString, false); | |
ClientCredential clientCred = new ClientCredential(clientId, clientSecret); | |
AuthenticationResult authenticationResult = null; | |
Task runTask = Task.Run(async () => authenticationResult = await authenticationContext.AcquireTokenAsync(resourceId, clientCred)); | |
runTask.Wait(); | |
string token = authenticationResult.AccessToken; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment