/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Security/samples/DynamicSchemes/Controllers/AuthController.cs
44 строки
1 KB
Pranav K
Use file scoped namespaces (#38076)
06 ноя 2021, 03:52
Не верифицирован
06 ноя 2021, 03:52
a450cb6
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; namespace AuthSamples.DynamicSchemes.Controllers; public class AuthController : Controller { private readonly IAuthenticationSchemeProvider _schemeProvider; private readonly IOptionsMonitorCache<SimpleOptions> _optionsCache; public AuthController(IAuthenticationSchemeProvider schemeProvider, IOptionsMonitorCache<SimpleOptions> optionsCache) { _schemeProvider = schemeProvider; _optionsCache = optionsCache; } public IActionResult Remove(string scheme) { _schemeProvider.RemoveScheme(scheme); _optionsCache.TryRemove(scheme); return Redirect("/"); } [HttpPost] public async Task<IActionResult> AddOrUpdate(string scheme, string optionsMessage) { if (await _schemeProvider.GetSchemeAsync(scheme) == null) { _schemeProvider.AddScheme(new AuthenticationScheme(scheme, scheme, typeof(SimpleAuthHandler))); } else { _optionsCache.TryRemove(scheme); } _optionsCache.TryAdd(scheme, new SimpleOptions { DisplayMessage = optionsMessage }); return Redirect("/"); } }