Example #1
0
        public async Task <List <Models.Message> > GetThreads(string teamid, string channelid)
        {
            var authProvider       = CreateClientCredentialProvider(this.azureADOptions.Value);
            var graphServiceClient = new Microsoft.Graph.GraphServiceClient(authProvider);
            HttpRequestMessage msg = new HttpRequestMessage(HttpMethod.Get, $"https://graph.microsoft.com/v1.0/teams/{teamid}/channels/{channelid}/messages");
            await authProvider.AuthenticateRequestAsync(msg);

            var response = await graphServiceClient.HttpProvider.SendAsync(msg);

            var json = await response.Content.ReadAsStringAsync();

            var    o = JObject.Parse(json);
            JArray a = (JArray)o["value"];
            List <Models.Message> messages = a.ToObject <List <Models.Message> >();

            // get replies for each message
            for (var i = 0; i < messages.Count; i++)
            {
                var m = new HttpRequestMessage(HttpMethod.Get, $"https://graph.microsoft.com/v1.0/teams/{teamid}/channels/{channelid}/messages/{messages[i].id}/replies");
                await authProvider.AuthenticateRequestAsync(m);

                var resp = await graphServiceClient.HttpProvider.SendAsync(m);

                json = await resp.Content.ReadAsStringAsync();

                o = JObject.Parse(json);
                a = (JArray)o["value"];
                messages[i].replies = a.ToObject <List <Models.Message> >();
            }

            return(messages);
        }
Example #2
0
 public ExchangeMailService(ProfileRegister register,
                            ExchangeProfileDataStore.Factory storeFactory,
                            MSGraph.GraphServiceClient client,
                            AM.IMapper mapper)
 {
     _register     = register;
     _storeFactory = storeFactory;
     _client       = client;
     _mapper       = mapper;
 }
Example #3
0
        private async Task <String[]> GetPropertyOwnersAsync(Graph.GraphServiceClient graphService)
        {
            var resturl        = "/_api/lists/GetByTitle('Properties')/Items?$select=sl_owner";
            var responseString = await RestHelper.GetDemoSiteJsonAsync(resturl, _token);

            var properties = JObject.Parse(responseString)["d"]["results"].ToObject <Property[]>();

            var users = await graphService.GetAllUsersAsync(properties.Select(i => i.sl_owner));

            return(users.Select(i => i.Mail).ToArray());
        }
Example #4
0
        public static void AUTH()
        {
            IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
                                                                           .Create(clientID)
                                                                           .WithTenantId(tenantID)
                                                                           .WithClientSecret(clientSecret)
                                                                           .Build();

            authProvider = new ClientCredentialProvider(confidentialClientApplication);
            graphClient  = new Microsoft.Graph.GraphServiceClient(authProvider);
            Console.WriteLine("AUTHED");
        }
Example #5
0
        public async Task <List <Models.Channel> > Get(string id)
        {
            var authProvider       = CreateClientCredentialProvider(this.azureADOptions.Value);
            var graphServiceClient = new Microsoft.Graph.GraphServiceClient(authProvider);
            var data = await graphServiceClient.Teams[id].Channels.Request().GetAsync();
            List <Models.Channel> items = new List <Models.Channel>();

            foreach (var item in data)
            {
                items.Add(new Models.Channel()
                {
                    id = item.Id, displayName = item.DisplayName, description = item.Description
                });
            }
            return(items);
        }
Example #6
0
        public static async Task CopyFileToTeams(string group_id, string item_id, string lcl_itempath)
        {
            var fileName      = lcl_itempath;
            var currentFolder = System.IO.Directory.GetCurrentDirectory();
            var filePath      = Path.Combine(currentFolder, fileName);

            FileStream fileStream = new FileStream(filePath, FileMode.Open);

            Microsoft.Graph.GraphServiceClient graphClient = new Microsoft.Graph.GraphServiceClient(authProvider);


            var response = await graphClient.Groups[group_id].Drive.Items[item_id].Content
                           .Request()
                           .PutAsync <DriveItem>(fileStream);

            Console.WriteLine(response);
            Console.WriteLine("downloaded file from teams");
        }
Example #7
0
        private static async Task <Graph.GraphServiceClient> GetGraphApiClient(ILogger log)
        {
            var azureServiceTokenProvider = new AzureServiceTokenProvider();

            string accessToken = await azureServiceTokenProvider
                                 .GetAccessTokenAsync("https://graph.microsoft.com/", Environment.GetEnvironmentVariable("AAD_TENANT"));

            var graphServiceClient = new Graph.GraphServiceClient(
                Graph.GraphClientFactory.Create(
                    new Graph.DelegateAuthenticationProvider((requestMessage) =>
            {
                requestMessage
                .Headers
                .Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", accessToken);

                return(Task.CompletedTask);
            }))
                );

            return(graphServiceClient);
        }
Example #8
0
        private async Task <HyperLink[]> GetMailsForDispatcherAsync(Graph.GraphServiceClient graphService, string CurrentUser)
        {
            List <HyperLink> result = new List <HyperLink>();

            var messages = await graphService.Users[CurrentUser].Messages.Request().GetAllAsync();

            var propertyOwners = await GetPropertyOwnersAsync(graphService);

            foreach (Graph.Message message in messages)
            {
                if (message.ToRecipients.Any(i => propertyOwners.Contains(i.EmailAddress.Address)))
                {
                    result.Add(new HyperLink
                    {
                        Title  = message.Subject,
                        WebUrl = message.WebLink
                    });
                    break;
                }
            }

            return(result.ToArray());
        }
Example #9
0
        public static GraphServiceClient GetGraphServiceClient()
        {
            GraphServiceClient graphClient = null;

            try
            {
                if (string.IsNullOrEmpty(appId) && string.IsNullOrEmpty(TenantId) && string.IsNullOrEmpty(clientSecret))
                {
                    //Add Logger
                    return(graphClient);
                }

                IConfidentialClientApplication clientApplication = ConfidentialClientApplicationBuilder
                                                                   .Create(appId)
                                                                   .WithTenantId(TenantId)
                                                                   .WithClientSecret(clientSecret)
                                                                   .WithClientVersion("V2")
                                                                   .Build();

                ClientCredentialProvider clientCredentialProvider = null;
                if (clientApplication != null)
                {
                    clientCredentialProvider = new ClientCredentialProvider(clientApplication);
                }

                if (clientCredentialProvider != null)
                {
                    graphClient = new Microsoft.Graph.GraphServiceClient(clientCredentialProvider);
                }
            }
            catch (Exception ex)
            {
                //Todo: Add Logger
                throw ex;
            }
            return(graphClient);
        }
Example #10
0
 public AccountController(Microsoft.Graph.GraphServiceClient graphclient, Microsoft.Extensions.Logging.ILogger <AccountController> logger)
 {
     _GraphServiceClient = graphclient ?? throw new System.ArgumentNullException("GraphServiceClient is missing");
     _Logger             = logger;
 }