2019-11-19 09:37:42 +00:00
|
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
2019-11-12 14:02:30 +00:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.Hosting;
|
2019-11-19 09:37:42 +00:00
|
|
|
using SpotifyAPI.Web.Enums;
|
2019-11-12 14:02:30 +00:00
|
|
|
|
|
|
|
namespace SpotifyAPI.Web.Examples.ASP
|
|
|
|
{
|
2020-03-09 19:47:39 +00:00
|
|
|
public class Startup
|
|
|
|
{
|
|
|
|
public Startup(IConfiguration configuration)
|
2019-11-12 14:02:30 +00:00
|
|
|
{
|
2020-03-09 19:47:39 +00:00
|
|
|
Configuration = configuration;
|
|
|
|
}
|
2019-11-12 14:02:30 +00:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
public IConfiguration Configuration { get; }
|
2019-11-12 14:02:30 +00:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
{
|
|
|
|
services.AddControllersWithViews();
|
2019-11-12 14:02:30 +00:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
services.AddAuthentication(o => o.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme)
|
|
|
|
.AddCookie()
|
|
|
|
.AddSpotify(options =>
|
|
|
|
{
|
|
|
|
var scopes = Scope.UserLibraryRead | Scope.UserModifyPlaybackState;
|
|
|
|
options.Scope.Add(scopes.GetStringAttribute(","));
|
2019-11-12 14:02:30 +00:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
options.SaveTokens = true;
|
|
|
|
options.ClientId = Configuration["client_id"];
|
|
|
|
options.ClientSecret = Configuration["client_secret"];
|
|
|
|
options.CallbackPath = "/callback";
|
|
|
|
});
|
|
|
|
}
|
2019-11-12 14:02:30 +00:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
|
|
{
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
{
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
app.UseExceptionHandler("/Home/Error");
|
|
|
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
|
|
|
app.UseHsts();
|
|
|
|
}
|
|
|
|
// app.UseHttpsRedirection();
|
|
|
|
app.UseStaticFiles();
|
2019-11-19 09:37:42 +00:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
app.UseRouting();
|
2019-11-12 14:02:30 +00:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
app.UseAuthentication();
|
|
|
|
app.UseAuthorization();
|
2019-11-19 09:37:42 +00:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
|
{
|
|
|
|
endpoints.MapControllerRoute(
|
|
|
|
name: "default",
|
|
|
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
|
|
|
});
|
2019-11-12 14:02:30 +00:00
|
|
|
}
|
2020-03-09 19:47:39 +00:00
|
|
|
}
|
|
|
|
}
|