/// <summary> /// Register google calendar /// </summary> /// <param name="serviceCollection"></param> /// <returns></returns> public static CalendarServiceCollection RegisterGoogleCalendarProvider(this CalendarServiceCollection serviceCollection) { serviceCollection.RegisterExternalCalendarProvider(options => { options.ProviderName = nameof(GoogleCalendarProvider); options.ProviderType = typeof(GoogleCalendarProvider); options.DisplayName = "Google"; options.FontAwesomeIcon = "google"; }); return(serviceCollection); }
/// <summary> /// Register outlook provider /// </summary> /// <param name="serviceCollection"></param> /// <param name="outlookOptions"></param> /// <returns></returns> public static CalendarServiceCollection RegisterOutlookCalendarProvider(this CalendarServiceCollection serviceCollection, Action <MsAuthorizationSettings> outlookOptions) { Arg.NotNull(outlookOptions, nameof(RegisterOutlookCalendarProvider)); serviceCollection.RegisterExternalCalendarProvider(options => { options.ProviderName = nameof(OutlookCalendarProvider); options.ProviderType = typeof(OutlookCalendarProvider); options.DisplayName = "Outlook"; options.FontAwesomeIcon = "microsoft"; }); var authSettings = new MsAuthorizationSettings(); outlookOptions(authSettings); OutlookAuthSettings.SetAuthSettings(authSettings); serviceCollection.Services.AddAuthentication() .AddMicrosoftAccount(microsoftOptions => { microsoftOptions.ClientId = authSettings.ClientId; microsoftOptions.ClientSecret = authSettings.ClientSecretId; microsoftOptions.SaveTokens = true; microsoftOptions.Events.OnCreatingTicket = ctx => { var tokens = ctx.Properties.GetTokens().ToList(); tokens.Add(new AuthenticationToken() { Name = "TicketCreated", Value = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture) }); ctx.Properties.StoreTokens(tokens); return(Task.CompletedTask); }; foreach (var scope in authSettings.Scopes) { microsoftOptions.Scope.Add(scope); } }); return(serviceCollection); }