/// <summary> /// Adds Spotify Authorization Code Flow message handler for native apps, implementation of <see cref="IAuthenticationManager"/> and other required services to the specified <see cref="IHttpClientBuilder"/>. /// </summary> /// <typeparam name="TOptions">The options type.</typeparam> /// <param name="httpClientBuilder">The <see cref="IHttpClientBuilder"/>.</param> /// <param name="configureOptions">Used to configure the <typeparamref name="TOptions"/>.</param> /// <returns></returns> public static ISpotifyAuthorizationCodeFlowCoreBuilder AddSpotifyAuthorizationCodeFlowCore <TOptions>(this IHttpClientBuilder httpClientBuilder, Action <TOptions> configureOptions) where TOptions : SpotifyAuthorizationCodeFlowOptions, new() { httpClientBuilder.Services .AddOptions <TOptions>().Validate(o => { o.Validate(); return(true); }) .Configure(configureOptions); httpClientBuilder.Services.TryAddSingleton <IOptionsProvider <TOptions>, OptionsProvider <TOptions> >(); httpClientBuilder.Services.TryAddSingleton <IOptionsProvider <SpotifyAuthorizationCodeFlowOptions> >(sp => sp.GetRequiredService <IOptionsProvider <TOptions> >()); httpClientBuilder.Services.TryAddSingleton <IAuthenticationTicketRepository, AuthenticationTicketRepository>(); httpClientBuilder.Services.TryAddSingleton <AuthenticationTicketProvider>(); httpClientBuilder.Services.TryAddSingleton <IAuthenticationTicketProvider>(sp => sp.GetRequiredService <AuthenticationTicketProvider>()); httpClientBuilder.Services.TryAddSingleton <IAuthenticationManager>(sp => sp.GetRequiredService <AuthenticationTicketProvider>()); httpClientBuilder.AddSpotifyAuthorizationFlowsCore(); httpClientBuilder.Services.TryAddSingleton <IOptionsProvider <ISpotifyAuthorizationClientOptions> >(sp => sp.GetRequiredService <IOptionsProvider <TOptions> >()); httpClientBuilder.Services.AddSpotifyAuthorizationClient(); httpClientBuilder.Services.TryAddSingleton <IOptionsProvider <ISpotifyTokenClientOptions> >(sp => sp.GetRequiredService <IOptionsProvider <TOptions> >()); var tokenHttpClientBuilder = httpClientBuilder.Services.AddSpotifyTokenClient(); httpClientBuilder.Services.TryAddSingleton <IOptionsProvider <ISpotifyUserClientOptions> >(sp => sp.GetRequiredService <IOptionsProvider <TOptions> >()); var userHttpClientBuilder = httpClientBuilder.Services.AddSpotifyUserClient(); return(new SpotifyAuthorizationCodeFlowCoreBuilder(tokenHttpClientBuilder, userHttpClientBuilder)); }
/// <summary> /// Adds Spotify Authorization Code Flow message handler for AspNetCore apps and other required services to the specified <see cref="IHttpClientBuilder"/>. /// </summary> /// <param name="httpClientBuilder">The <see cref="IHttpClientBuilder"/>.</param> /// <param name="authenticationScheme">The authentication scheme.</param> /// <param name="spotifyAuthenticationScheme">The Spotify authentication scheme.</param> /// <returns></returns> public static ISpotifyAuthorizationCodeFlowBuilder AddSpotifyAuthorizationCodeFlow( this IHttpClientBuilder httpClientBuilder, string authenticationScheme = null, string spotifyAuthenticationScheme = null) { httpClientBuilder.Services.AddHttpContextAccessor(); httpClientBuilder.Services.TryAddSingleton <IClock, ClockFromSystemClock>(); httpClientBuilder.Services.TryAddSingleton <ISemaphoreProvider, SemaphoreProvider>(); httpClientBuilder.Services.TryAddScoped <SemaphoreWrapper>(); httpClientBuilder.Services.TryAddSingleton <IAuthenticationManager>(sp => new AuthenticationManager(sp.GetRequiredService <IHttpContextAccessor>(), authenticationScheme)); httpClientBuilder.Services.TryAddSingleton <IAuthenticationTicketProvider, AuthenticationTicketProvider>(); httpClientBuilder.AddSpotifyAuthorizationFlowsCore(); httpClientBuilder.Services.TryAddSingleton <IOptionsProvider <ISpotifyTokenClientOptions> >(sp => new AuthorizationCodeFlowOptionsProvider(sp.GetRequiredService <IHttpContextAccessor>(), spotifyAuthenticationScheme)); var tokenHttpClientBuilder = httpClientBuilder.Services.AddSpotifyTokenClient(); var builder = new SpotifyAuthorizationCodeFlowBuilder(tokenHttpClientBuilder); return(builder); }
/// <summary> /// Adds Spotify Client Credentials Flow message handler and required services to the specified <see cref="IHttpClientBuilder"/>. /// </summary> /// <param name="httpClientBuilder">The <see cref="IHttpClientBuilder"/>.</param> /// <param name="configureOptions">Used to configure the <see cref="SpotifyClientCredentialsFlowOptions"/>.</param> public static ISpotifyClientCredentialsFlowBuilder AddSpotifyClientCredentialsFlow(this IHttpClientBuilder httpClientBuilder, Action <SpotifyClientCredentialsFlowOptions> configureOptions) { httpClientBuilder.Services .AddOptions <SpotifyClientCredentialsFlowOptions>().Validate(o => { o.Validate(); return(true); }) .Configure(configureOptions); httpClientBuilder.Services.TryAddSingleton <IAuthenticationTicketProvider, AuthenticationTicketProvider>(); httpClientBuilder.AddSpotifyAuthorizationFlowsCore(); httpClientBuilder.Services.TryAddSingleton <IOptionsProvider <ISpotifyTokenClientOptions>, OptionsProvider <SpotifyClientCredentialsFlowOptions> >(); var tokenHttpClientBuilder = httpClientBuilder.Services.AddSpotifyTokenClient(); var builder = new SpotifyClientCredentialsFlowBuilder(tokenHttpClientBuilder); return(builder); }