This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react'; | |
const Timer = () => { | |
const [seconds, setSeconds] = useState(0); | |
const [isActive, setIsActive] = useState(false); | |
const handleTimerClick = () => { | |
setIsActive(!isActive); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<li class="nav-item"> | |
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Secure">Secure</a> | |
</li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@{ | |
ViewData["Title"] = "Secure"; | |
} | |
<h1>@ViewData["Title"]</h1> | |
<p>Use this page to show sensitive information that should only be shown to an authenticated user.</p> | |
<div> | |
<h4>Profile Pic</h4> | |
<img src=@Model.ProfileURL class="profile-pic"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace asp.net_core_boilerplte.Models | |
{ | |
public class Secure | |
{ | |
public IEnumerable<System.Security.Claims.Claim>? Claims { get; set; } | |
public string? AccessToken { get; set; } | |
public string? IdToken { get; set; } | |
public string? RefreshToken { get; set; } | |
public string? DisplayName { get; set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Authorize] | |
public async Task<IActionResult> Secure() | |
{ | |
var accessToken = await HttpContext.GetTokenAsync("access_token"); | |
var idToken = await HttpContext.GetTokenAsync("id_token"); | |
var refreshToken = await HttpContext.GetTokenAsync("refresh_token"); | |
string displayName = UserUtils.GetDisplayName(User); | |
IEnumerable<System.Security.Claims.Claim> claims = User.Claims; | |
// Getting the profile picture URL from the userinfo endpoint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace asp.net_core_boilerplte.Utils | |
{ | |
public static class UserUtils | |
{ | |
public static string GetDisplayName(System.Security.Claims.ClaimsPrincipal user) | |
{ | |
try | |
{ | |
return user?.Claims?.Where(claim => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using asp.net_core_boilerplte.Utils; | |
<ul class="navbar-nav"> | |
@if (User?.Identity?.IsAuthenticated == true) | |
{ | |
<li class="nav-item"> | |
<a class="nav-link text-dark" title="Manage">Hello @UserUtils.GetDisplayName(User)!</a> | |
</li> | |
<li class="nav-item"> | |
<a class="nav-link text-dark" asp-area="" asp-controller="Identity" asp-action="Logout">Logout</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Authentication; | |
using Microsoft.AspNetCore.Authentication.Cookies; | |
using Microsoft.AspNetCore.Authentication.OpenIdConnect; | |
using Microsoft.AspNetCore.Mvc; | |
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Authentication.Cookies; | |
using Microsoft.AspNetCore.Authentication.OpenIdConnect; | |
using Microsoft.IdentityModel.Protocols.OpenIdConnect; | |
using Microsoft.Extensions.Configuration; | |
IConfiguration Configuration = new ConfigurationBuilder() | |
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory) | |
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) | |
.Build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.UseAuthentication(); | |
app.UseAuthorization(); |