public StravaSubscriptionService( IStravaClient stravaClient, IOptions <StravaSettings> settings, IDistributedCache cache) { _stravaClient = stravaClient; _stravaSettings = settings.Value; _cache = cache; }
public StravaAuthenticationService( IIntegrationRepository integrationRepository, IDateTimeProvider dateTimeProvider, IStravaClient stravaClient, IOptions <StravaSettings> stravaSettings) { _integrationRepository = integrationRepository; _dateTimeProvider = dateTimeProvider; _stravaClient = stravaClient; _stravaSettings = stravaSettings.Value; }
public StravaClient(HttpClient httpClient, IOptions <StravaSettings> stravaSettings) { _httpClient = httpClient; _stravaSettings = stravaSettings.Value; _jsonSerializerOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; _jsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); }
public StravaSettings BuildStravaSettings() { var stravaSettings = new StravaSettings(); try { stravaSettings = _configuration.GetSection("Strava").Get <StravaSettings>(); } catch { } if (stravaSettings.ClientId == default) { stravaSettings = new StravaSettings { ClientId = int.Parse(Environment.GetEnvironmentVariable("StravaClientId")), ClientSecret = Environment.GetEnvironmentVariable("StravaClientSecret") }; } return(stravaSettings); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { var cfgBuilder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile($"appsettings.json", true, true) .AddJsonFile($"appsettings.dev.json", true, true) .AddJsonFile($"local.settings.json", true, true) .AddEnvironmentVariables(); var configuration = cfgBuilder.Build(); var stravaSettings = new StravaSettings(); configuration.GetSection("strava").Bind(stravaSettings); var logSettings = new LogSettings(); configuration.GetSection("logging").Bind(logSettings); var apiSettings = new CotacolApiSettings(); configuration.GetSection("api").Bind(apiSettings); var kvSettings = new KeyVaultSettings(); configuration.GetSection("keyvault").Bind(kvSettings); services.AddDbContext <ApplicationDbContext>(options => options.UseSqlite( Configuration.GetConnectionString("DefaultConnection"))); services.AddDefaultIdentity <CotacolUser>(options => { options.SignIn.RequireConfirmedAccount = false; options.SignIn.RequireConfirmedEmail = false; options.SignIn.RequireConfirmedPhoneNumber = false; }) .AddEntityFrameworkStores <ApplicationDbContext>(); services.AddRazorPages(); services.AddServerSideBlazor().AddHubOptions(config => config.MaximumReceiveMessageSize = 1048576); if (!string.IsNullOrEmpty(kvSettings?.KeySasBlobUri)) { services.AddDataProtection() // .PersistKeysToFileSystem(new DirectoryInfo("/Users/samvanhoutte/Temp/bbb/ee")); .PersistKeysToAzureBlobStorage(new Uri($"{kvSettings.KeySasBlobUri}")) .ProtectKeysWithAzureKeyVault(new Uri(kvSettings.KeyKeyvaultUri), new DefaultAzureCredential()); // .PersistKeysToFileSystem(new DirectoryInfo(Configuration["KeyPersistenceLocation"])); } // Strava authentication services.AddAuthentication(options => { //options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; //options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultChallengeScheme = "Strava"; }) .AddCookie() .AddOAuth("Strava", "Strava", options => { options.ClientId = stravaSettings.ClientId; options.ClientSecret = stravaSettings.ClientOauthSecret; options.CallbackPath = "/stravalogin"; //"/signin-strava"; options.SaveTokens = true; // Save the auth/refresh token for later retrieval options.SignInScheme = IdentityConstants.ExternalScheme; options.AuthorizationEndpoint = "https://www.strava.com/oauth/authorize"; options.TokenEndpoint = stravaSettings.AccessTokenUrl; options.UserInformationEndpoint = "https://www.strava.com/api/v3/athlete"; options.Scope.Clear(); options.Scope.Add( "read,read_all,activity:read_all,activity:read,activity:write,profile:write"); options.Events = new OAuthEvents { OnCreatingTicket = async context => { var request = new HttpRequestMessage(HttpMethod.Get, context.Options.UserInformationEndpoint); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", context.AccessToken); var response = await context.Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, context.HttpContext.RequestAborted); response.EnsureSuccessStatusCode(); var claimsJson = await response.Content.ReadAsStringAsync(); //context.RunClaimActions(user.RootElement); var userSettings = context.AddClaims(claimsJson); } }; options.Validate(); }); services.AddHttpContextAccessor(); // Dependency injection services .AddScoped <AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider <CotacolUser> >(); services.AddDatabaseDeveloperPageExceptionFilter(); services.AddOptions(); services.AddLogging(loggingbuilder => { loggingbuilder.ClearProvidersExceptFunctionProviders(); if (!string.IsNullOrEmpty(logSettings.ApplicationInsightsInstrumentationKey)) { loggingbuilder.AddSerilog( CreateLogConfiguration(logSettings.ApplicationInsightsInstrumentationKey)); } }); services.AddScoped <IUserProfileManager, CotacolProfileManager>(); services.AddSingleton <WeatherForecastService>(); services.AddSingleton <ICotacolClient, CotacolApiClient>(); services.AddSingleton <ICotacolUserClient, CotacolApiUserClient>(); services.AddSingleton <ISecretReader, KeyVaultReader>(); services.AddMatBlazor(); services .Configure <CotacolApiSettings>(options => configuration.GetSection("api").Bind(options)) .Configure <StravaSettings>(options => configuration.GetSection("strava").Bind(options)) .Configure <KeyVaultSettings>(options => configuration.GetSection("keyvault").Bind(options)); // Inject HttpClient, required by MatBlazor components if (services.All(x => x.ServiceType != typeof(HttpClient))) { services.AddScoped( s => { var navigationManager = s.GetRequiredService <NavigationManager>(); return(new HttpClient { BaseAddress = new Uri(navigationManager.BaseUri) }); }); } }
public StravaWebhookController(IOptions <StravaSettings> stravaSettings, IMediator mediator) { this.stravaSettings = stravaSettings.Value; this.mediator = mediator; }