implemented Discord OAuth2

This commit is contained in:
t.ruspekhofer 2022-02-13 20:40:15 +01:00
parent 9365e22874
commit dbf1be4c5d
18 changed files with 195 additions and 133 deletions

View file

@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Mvc;
namespace Lieb.Data
{
[Route("[controller]/[action]")] // Microsoft.AspNetCore.Mvc.Route
public class AccountController : ControllerBase
{
public IDataProtectionProvider Provider { get; }
public AccountController(IDataProtectionProvider provider)
{
Provider = provider;
}
[HttpGet]
public IActionResult Login(string returnUrl = "/")
{
return Challenge(new AuthenticationProperties { RedirectUri = returnUrl }, "Discord");
}
[HttpGet]
public async Task<IActionResult> Logout(string returnUrl = "/")
{
//This removes the cookie assigned to the user login.
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
return LocalRedirect(returnUrl);
}
}
}

View file

@ -1,13 +0,0 @@
namespace Lieb.Data
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}

View file

@ -1,20 +0,0 @@
namespace Lieb.Data
{
public class WeatherForecastService
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
{
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
}).ToArray());
}
}
}