|
| 1 | +using Microsoft.AspNetCore.Authentication; |
| 2 | +using Microsoft.AspNetCore.Authentication.Cookies; |
| 3 | +using Microsoft.AspNetCore.Authentication.OpenIdConnect; |
| 4 | +using Microsoft.AspNetCore.Authorization; |
| 5 | +using Microsoft.AspNetCore.Mvc; |
| 6 | + |
| 7 | +/* |
| 8 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 9 | + * SPDX-License-Identifier: MIT-0 |
| 10 | + * |
| 11 | + * Permission is hereby granted, free of charge, to any person obtaining a copy of this |
| 12 | + * software and associated documentation files (the "Software"), to deal in the Software |
| 13 | + * without restriction, including without limitation the rights to use, copy, modify, |
| 14 | + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to |
| 15 | + * permit persons to whom the Software is furnished to do so. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
| 18 | + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
| 19 | + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 20 | + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 21 | + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 22 | + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 | + */ |
| 24 | + |
| 25 | +namespace AWS.Samples.Amazon.Cognito.Demo.Controllers |
| 26 | +{ |
| 27 | + public class ProductsController : Controller |
| 28 | + { |
| 29 | + // GET: /<controller>/ |
| 30 | + [Authorize] |
| 31 | + [HttpGet] |
| 32 | + public IActionResult Index() |
| 33 | + { |
| 34 | + return View(); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + public class ExternalAuthenticationController : Controller |
| 39 | + { |
| 40 | + public IActionResult CallBack() |
| 41 | + { |
| 42 | + //caputure the user object |
| 43 | + return RedirectToAction("Index", "Products"); |
| 44 | + } |
| 45 | + |
| 46 | + public IActionResult SignOut() |
| 47 | + { |
| 48 | + var callbackUrl = Url.Page("/", pageHandler: null, values: null, protocol: Request.Scheme); |
| 49 | + return SignOut( |
| 50 | + new AuthenticationProperties { RedirectUri = callbackUrl }, |
| 51 | + CookieAuthenticationDefaults.AuthenticationScheme, OpenIdConnectDefaults.AuthenticationScheme |
| 52 | + ); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments