using System;
using System.Threading.Tasks;
using System.Security.Claims;
using Microsoft.AspNetCore.Components.Authorization;

using CommonHelpers.WASM;
using AFXUI;

namespace BookRegistry.Client {

//**************************************************************************************************
public class CustomAuthStateProvider: AuthenticationStateProvider {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public override Task<AuthenticationState> GetAuthenticationStateAsync()
{
   var claims = Session.IsOpen ?
      new []{
         new Claim( ClaimTypes.Name, Session.UserName ),
         new Claim( ClaimTypes.Role, Session.RoleName ) } :
      new Claim[0];
/*
   if ( !Session.IsOpen )
      claims = new []{
         new Claim( ClaimTypes.Name, "user1" ),
         new Claim( ClaimTypes.Role, "General" ) };
*/
   var identity = new ClaimsIdentity( claims, "Authentication with two roles" );
   var user = new ClaimsPrincipal( identity );
   return Task.FromResult( new AuthenticationState( user ) );
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // CustomAuthStateProvider
//**************************************************************************************************

} // BookRegistry.Client
