public SpotifyRunConfig(LavaRestClient lavaRest, SpotifyWebAPI api, SpotifyConfig config, SpotifyTrackConverter trackConverter) { this.LavaRest = lavaRest; this.Api = api; this.Config = config; this.TrackConverter = trackConverter; }
public SpotifyService(HttpClient client, SpotifyConfig spotifyConfig) { client.BaseAddress = new Uri("https://api.spotify.com"); client.DefaultRequestHeaders.Add("Accept", "application/json"); client.DefaultRequestHeaders.Add("Authorization", $"Bearer {spotifyConfig.ApiToken}"); _client = client; }
public HomeController( IAuthenticationService authService, IOptions <SpotifyConfig> spotifyConfig) { _authService = authService; this._spotifyConfig = spotifyConfig?.Value ?? throw new ArgumentNullException(nameof(spotifyConfig)); }
public static IServiceCollection AddSpotifyProxy(this IServiceCollection services, string clientId, string secret) { var config = new SpotifyConfig { ClientId = clientId, Secret = secret }; services.AddSingleton(Options.Options.Create(config)); return(services.AddSpotifyProxy()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); services.AddSingleton <JsonStorage>(); services.AddScoped <IUrlRepository, UrlRepository>(); services.AddScoped <IUrlShortener, UrlShortener>(); var spotifyClientId = Configuration.GetValue <string>("Spotify:ClientId"); var spotifyClientSecret = Configuration.GetValue <string>("Spotify:ClientSecret"); var spotifyMyUserId = Configuration.GetValue <string>("Spotify:MyUserId"); var spotifyConfig = new SpotifyConfig(spotifyClientId, spotifyClientSecret, spotifyMyUserId); services.AddSingleton <SpotifyApi>(p => new SpotifyApi(spotifyConfig)); services.AddTransient <ISpotifyService, SpotifyService>(); }
public SpotifyService(ILogger <SpotifyService> logger, IUserService userService, IArtistService artistService, IOptions <SpotifyConfig> config) { _logger = logger; _spotifyConfig = config.Value; _client = new HttpClient { DefaultRequestHeaders = { Accept = { new MediaTypeWithQualityHeaderValue("application/json") } } }; _serializerOptions = new JsonSerializerOptions { PropertyNamingPolicy = new JsonSnakeCaseNamingPolicy() }; _userService = userService; _artistService = artistService; }
public SpotifyHandlerService(EnergizeClient client) { this.Logger = client.Logger; this.Api = new SpotifyWebAPI { TokenType = "Bearer", UseAuth = true, UseAutoRetry = true }; this.LavaRest = GetLavaRestClient(); // TODO: add configuration entry this.Config = Essentials.Config.Instance.Spotify; this.SpotifyAuthTimer = new Timer(this.TradeSpotifyToken); SpotifyRunConfig spotifyRunConfig = new SpotifyRunConfig(this.LavaRest, this.Api, this.Config, new SpotifyTrackConverter(this.LavaRest, this.Config)); this.TrackProvider = new SpotifyTrackProvider(spotifyRunConfig); this.SearchProvider = new SpotifySearchProvider(spotifyRunConfig); this.PlaylistProvider = new SpotifyPlaylistProvider(spotifyRunConfig); this.AlbumProvider = new SpotifyAlbumProvider(spotifyRunConfig); this.ArtistProvider = new SpotifyArtistProvider(spotifyRunConfig); }
public Auth(IOptions <SpotifyConfig> spotifyConfig) { _spotifyConfig = spotifyConfig.Value; }
public SincronizarSpotifyHandler(IMediatorHandler bus, IDiscoQueries discoQueries, SpotifyConfig config) { _bus = bus; _discoQueries = discoQueries; _config = config; }
public SpotifyTrackConverter(LavaRestClient lavaRest, SpotifyConfig config) { this.LavaRest = lavaRest; this.Config = config; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy(DevCorsPolicy, builder => { builder .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); }); }); services.AddControllers(); var builder = new SqlConnectionStringBuilder( Configuration.GetConnectionString("DB")); services.AddDbContextPool <BangerShareContext>(options => options .UseSqlServer(builder.ConnectionString)); services.AddScoped <UserService>(); services.AddScoped <PlaylistService>(); services.AddScoped <SongService>(); services.AddScoped <FriendService>(); services.AddScoped <SpotifyAPIService>(); services.AddScoped <YoutubeAPIService>(); services.AddScoped <IRepository <User>, UserRepository>(); services.AddScoped <IRepository <UserPlaylist>, UserPlaylistRepository>(); services.AddScoped <IRepository <Playlist>, PlaylistRepository>(); services.AddScoped <IRepository <UserLike>, UserLikeRepository>(); services.AddScoped <FriendRepository>(); services.AddScoped <SongRepository>(); services.AddScoped <IUnitOfWork, UnitOfWork <BangerShareContext> >(); services.AddSingleton <IPasswordHasher, PasswordHasher>(); services.AddSingleton <ITokenHandler, Security.Tokens.TokenHandler>(); services.AddScoped <IAuthenticationService, AuthenticationService>(); var spoitfyConfig = new SpotifyConfig(); Configuration.Bind("Spotify", spoitfyConfig); services.AddSingleton(spoitfyConfig); var youtubeConfig = new YoutubeConfig(); Configuration.Bind("Youtube", youtubeConfig); services.AddSingleton(youtubeConfig); services.Configure <TokenOptions>(Configuration.GetSection("TokenOptions")); var tokenOptions = Configuration.GetSection("TokenOptions").Get <TokenOptions>(); var signingConfigurations = new SigningConfigurations(); services.AddSingleton(signingConfigurations); // middleware used to validate access token in header of requests services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(jwtBearerOptions => { jwtBearerOptions.TokenValidationParameters = new TokenValidationParameters() { ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = tokenOptions.Issuer, ValidAudience = tokenOptions.Audience, IssuerSigningKey = signingConfigurations.Key, ClockSkew = TimeSpan.Zero }; }); services.AddAutoMapper(typeof(Startup)); // swagger services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "BangerShare API", Version = "v1" }); // allows for authorization in swagger c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = "JWT Authorization header using the Bearer scheme. " + Environment.NewLine + "Enter 'Bearer' [space] and then your token in the text input below. " + Environment.NewLine + "Example: 'Bearer 12345abcdef'", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey, Scheme = "Bearer" }); c.AddSecurityRequirement(new OpenApiSecurityRequirement() { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" }, Scheme = "oauth2", Name = "Bearer", In = ParameterLocation.Header, }, new List <string>() } }); }); }