Liz posted: " Mel is a biking enthusiast and it is her birthday. Amanda has just become Ladies' Club Champion the the golf club and so a double celebration was in order. Mel's side of the cake is chocolate sponge with chocolate fudge filling and Amanda's, a lemon spon"
Mel is a biking enthusiast and it is her birthday. Amanda has just become Ladies' Club Champion the the golf club and so a double celebration was in order. Mel's side of the cake is chocolate sponge with chocolate fudge filling and Amanda's, a lemon sponge filled with fresh lemon curd and buttercream. On the top, a fancy bike and Amanda's trophy, around the sides the landscape of road cycling and the golf course. I hope you had a great night girls
tomaztsql posted: " Plot() function is R's most generic function for plotting different types of graphs. And making a animation of sample graphs with is as useless as it can be useful for educational purposes. Animation would look like this: Useless plot()"
Plot() function is R's most generic function for plotting different types of graphs. And making a animation of sample graphs with is as useless as it can be useful for educational purposes.
Animation would look like this:
So the gist of the function is two-fold:
Data and description of the graph
Animation created from png files stored in temporary folder (tested on Windows and Unix)
library(magick) set.seed(2908) plot_animation <- function(SavePath){ # create a temporary directory to store plot files dir_out <- file.path(tempdir(), "ShowCaseTempFolder") dir.create(dir_out, recursive = TRUE) # general data AllData <- data.frame(graph=c ( "plot(ScatterData, main = 'Scatterplot')" ,"plot(BarData, main = 'Histogram')" ,"plot(BarData, rnorm(150), main = 'Boxplot')" ,"plot(TimeSeriesData, main = 'Time-series')" ,"plot(FunctionData, -10, 5*pi, main = 'Plot a function')" ,"plot(IrisData, main = 'Correlation plot for two variables')" ,"plot(IrisData, main = 'Correlation plot for two variables with lines of SS') lines(lowess(iris[,1:2]))" ,"plot(IrisData3, main = 'Correlation plot for three or more')" ), data=c('ScatterData <- cbind(rnorm(200),rnorm(200) * rnorm(200) + rnorm(200))' ,'BarData <- factor(iris$Sepal.Width)' ,'BarData <- factor(iris$Sepal.Width)' ,'TimeSeriesData <- ts(matrix(rnorm(300), nrow = 300, ncol = 1), start = c(1990, 1), frequency = 12)' ,'FunctionData <- function(x) {x^4*pi}' ,'IrisData <- as.data.frame(iris[, 1:2])' ,'IrisData <- as.data.frame(iris[, 1:2])' ,'IrisData3 <- as.data.frame(iris[, 1:3])' ) ) for (i in 1:nrow(AllData)) { graphinfo <- as.character(AllData$graph[i]) datainfo <- as.character(AllData$data[i]) eval(parse(text=datainfo)) name_p <- paste0(dir_out,'\\',i,'.png') png(name_p) par(mfrow=c(3,1)) p <- eval(parse(text=graphinfo)) plot(c(0, 1), c(0, 1), ann = FALSE, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n') text(x = 0.5, y = 0.5, paste("Graph code: ", graphinfo), cex = 1.5, col = "Darkgreen", font=1, adj=0.5) plot(c(0, 1), c(0, 1), ann = FALSE, bty = 'n', type = 'n', xaxt = 'n', yaxt = 'n') text(x = 0.5, y = 0.5, paste("Data script: ",datainfo), cex = 1.5, col = "Darkblue", font=1, adj=0.5) par(mfrow=c(1,1)) dev.off() } # Render animation and store to disk plot_animation <- image_animate(image_join(lapply(list.files(dir_out, full.names = TRUE), image_read)), fps = 0.5) image_write(image = plot_animation,path = SavePath) unlink(dir_out, recursive=TRUE) }
And to run the function with inputing the final location where you want the animation to be stored.
damienbod posted: " This article shows how to create Microsoft Teams meetings in ASP.NET Core using Microsoft Graph with application permissions. This is useful if you have a designated account to manage or create meetings, send emails or would like to provide a service for"
This article shows how to create Microsoft Teams meetings in ASP.NET Core using Microsoft Graph with application permissions. This is useful if you have a designated account to manage or create meetings, send emails or would like to provide a service for users without an office account to create meetings. This is a follow up post to part one in this series which creates Teams meetings using delegated permissions.
A simple ASP.NET Core application with no authentication was created and implements a form which creates online meetings on behalf of a designated account using Microsoft Graph with application permissions. The Microsoft Graph client uses an Azure App registration for authorization and the client credentials flow is used to authorize the client and get an access token. No user is involved in this flow and the application requires administration permissions in the Azure App registration for Microsoft Graph.
An Azure App registration is setup to authenticate against Azure AD. The ASP.NET Core application will use application permissions for the Microsoft Graph. The listed permissions underneath are required to create the Teams meetings OBO and to send emails to the attendees using the configuration email which has access to office.
Microsoft Graph application permissions:
User.Read.All
Mail.Send
Mail.ReadWrite
OnlineMeetings.ReadWrite.All
This is the list of permissions I have activate for this demo.
Configuration
The Azure AD configuration is used to get a new access token for the Microsoft Graph client and to define the email of the account which is used to create Microsoft Teams meetings and also used to send emails to the attendees. This account needs an office account.
"AzureAd": { "TenantId": "5698af84-5720-4ff0-bdc3-9d9195314244", "ClientId": "b9be5f88-f629-46b0-ac4c-c5a4354ac192", // "ClientSecret": "add secret to the user secrets" "MeetingOrganizer": "--your-email-for-sending--" },
Setup Client credentials flow to for Microsoft Graph
A number of different ways can be used to authorize a Microsoft Graph client and is a bit confusing sometimes. Using the DefaultCredential is not really a good idea for Graph because you need to decide if you use a delegated authorization or a application authorization and the DefaultCredential will take the first one which works and this depends on the environment. For application authorization, I use the ClientSecretCredential Identity to get the service access token. This requires the .default scope and a client secret or a client credential. Using a client secret is fine if you control both client and server and the secret is stored in an Azure Key Vault. A client certificate could also be used.
private GraphServiceClient GetGraphClient() { string[] scopes = new[] { "https://graph.microsoft.com/.default" }; var tenantId = _configuration["AzureAd:TenantId"]; // Values from app registration var clientId = _configuration.GetValue<string>("AzureAd:ClientId"); var clientSecret = _configuration.GetValue<string>("AzureAd:ClientSecret"); var options = new TokenCredentialOptions { AuthorityHost = AzureAuthorityHosts.AzurePublicCloud }; // https://docs.microsoft.com/dotnet/api/azure.identity.clientsecretcredential var clientSecretCredential = new ClientSecretCredential( tenantId, clientId, clientSecret, options); return new GraphServiceClient(clientSecretCredential, scopes); }
The IConfidentialClientApplication interface could also be used to get access tokens which is used to authorize the Graph client. A simple in memory cache is used to store the access token. This token is reused until it expires or the application is restart. If using multiple instances, maybe a distributed cache would be better. The client uses the "https://graph.microsoft.com/.default" scope to get an access token for the Microsoft Graph client. A GraphServiceClient instance is returned with a value access token.
public class ApiTokenInMemoryClient { private readonly IHttpClientFactory _clientFactory; private readonly ILogger<ApiTokenInMemoryClient> _logger; private readonly IConfiguration _configuration; private readonly IConfidentialClientApplication _app; private readonly ConcurrentDictionary<string, AccessTokenItem> _accessTokens = new(); private class AccessTokenItem { public string AccessToken { get; set; } = string.Empty; public DateTime ExpiresIn { get; set; } } public ApiTokenInMemoryClient(IHttpClientFactory clientFactory, IConfiguration configuration, ILoggerFactory loggerFactory) { _clientFactory = clientFactory; _configuration = configuration; _logger = loggerFactory.CreateLogger<ApiTokenInMemoryClient>(); _app = InitConfidentialClientApplication(); } public async Task<GraphServiceClient> GetGraphClient() { var result = await GetApiToken("default"); var httpClient = _clientFactory.CreateClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var graphClient = new GraphServiceClient(httpClient) { AuthenticationProvider = new DelegateAuthenticationProvider(async (requestMessage) => { requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result); await Task.FromResult<object>(null); }) }; return graphClient; } private async Task<string> GetApiToken(string api_name) { if (_accessTokens.ContainsKey(api_name)) { var accessToken = _accessTokens.GetValueOrDefault(api_name); if (accessToken.ExpiresIn > DateTime.UtcNow) { return accessToken.AccessToken; } else { // remove _accessTokens.TryRemove(api_name, out _); } } _logger.LogDebug($"GetApiToken new from STS for {api_name}"); // add var newAccessToken = await AcquireTokenSilent(); _accessTokens.TryAdd(api_name, newAccessToken); return newAccessToken.AccessToken; } private async Task<AccessTokenItem> AcquireTokenSilent() { //var scopes = "User.read Mail.Send Mail.ReadWrite OnlineMeetings.ReadWrite.All"; var authResult = await _app .AcquireTokenForClient(scopes: new[] { "https://graph.microsoft.com/.default" }) .WithAuthority(AzureCloudInstance.AzurePublic, _configuration["AzureAd:TenantId"]) .ExecuteAsync(); return new AccessTokenItem { ExpiresIn = authResult.ExpiresOn.UtcDateTime, AccessToken = authResult.AccessToken }; } private IConfidentialClientApplication InitConfidentialClientApplication() { return ConfidentialClientApplicationBuilder .Create(_configuration["AzureAd:ClientId"]) .WithClientSecret(_configuration["AzureAd:ClientSecret"]) .Build(); } }
OnlineMeetings Graph Service
The AadGraphApiApplicationClient service is used to send the Microsoft Graph requests. This uses the graphServiceClient client with the correct access token. The GetUserIdAsync method is used to get the Graph Id using the UPN. This is used in the Users API to run the requests with the application scopes. The Me property is not used as this is for delegated scopes. We have no user in this application. We run the requests as an application on behalf of the designated user.
public class AadGraphApiApplicationClient { private readonly IConfiguration _configuration; public AadGraphApiApplicationClient(IConfiguration configuration) { _configuration = configuration; } private async Task<string> GetUserIdAsync() { var meetingOrganizer = _configuration["AzureAd:MeetingOrganizer"]; var filter = $"startswith(userPrincipalName,'{meetingOrganizer}')"; var graphServiceClient = GetGraphClient(); var users = await graphServiceClient.Users .Request() .Filter(filter) .GetAsync(); return users.CurrentPage[0].Id; } public async Task SendEmailAsync(Message message) { var graphServiceClient = GetGraphClient(); var saveToSentItems = true; var userId = await GetUserIdAsync(); await graphServiceClient.Users[userId] .SendMail(message, saveToSentItems) .Request() .PostAsync(); } public async Task<OnlineMeeting> CreateOnlineMeeting(OnlineMeeting onlineMeeting) { var graphServiceClient = GetGraphClient(); var userId = await GetUserIdAsync(); return await graphServiceClient.Users[userId] .OnlineMeetings .Request() .AddAsync(onlineMeeting); } public async Task<OnlineMeeting> UpdateOnlineMeeting(OnlineMeeting onlineMeeting) { var graphServiceClient = GetGraphClient(); var userId = await GetUserIdAsync(); return await graphServiceClient.Users[userId] .OnlineMeetings[onlineMeeting.Id] .Request() .UpdateAsync(onlineMeeting); } public async Task<OnlineMeeting> GetOnlineMeeting(string onlineMeetingId) { var graphServiceClient = GetGraphClient(); var userId = await GetUserIdAsync(); return await graphServiceClient.Users[userId] .OnlineMeetings[onlineMeetingId] .Request() .GetAsync(); } private GraphServiceClient GetGraphClient() { string[] scopes = new[] { "https://graph.microsoft.com/.default" }; var tenantId = _configuration["AzureAd:TenantId"]; // Values from app registration var clientId = _configuration.GetValue<string>("AzureAd:ClientId"); var clientSecret = _configuration.GetValue<string>("AzureAd:ClientSecret"); var options = new TokenCredentialOptions { AuthorityHost = AzureAuthorityHosts.AzurePublicCloud }; // https://docs.microsoft.com/dotnet/api/azure.identity.clientsecretcredential var clientSecretCredential = new ClientSecretCredential( tenantId, clientId, clientSecret, options); return new GraphServiceClient(clientSecretCredential, scopes); } }
The startup class adds the services as required. No authentication is added for the ASP.NET Core application.
When the application is started, you can create a new Teams meeting with the required details. The configuration email must have an account with access to Office and be on the same tenant as the Azure App registration setup for the Microsoft Graph application permissions. The Email must have a policy setup to allow the Microsoft Graph calls. The Teams meeting is organized using the identity that signed in because we used the applications permissions.
This works really well and can be used for Azure B2C solutions as well. If possible, you should only use delegated scopes in the application, if possible. By using application permissions, the ASP.NET Core is implicitly an administrator of these permissions as well. It would be better if user accounts with delegated access was used which are managed by your IT etc.