Chould you give me more infomation about how to do it ? like step by step. what i need to do in both blazor and AuthServer? thanks a lot.
I know they use Cookie or OpenID Connect , But I'd like to Know how Blazor Server and WASM implement Passwordless Login with auth server.
hi maliming how Blazor Server or WASM implement passwordless login. like use a link redrickt to Blazor Server and keep a user login. I had a EmployeeNumberGrantHandler too. ` public class EmployeeNumberGrantHandler : IOpenIddictServerHandler<OpenIddictServerEvents.HandleTokenRequestContext> { public static OpenIddictServerHandlerDescriptor Descriptor { get; } = OpenIddictServerHandlerDescriptor.CreateBuilder<OpenIddictServerEvents.HandleTokenRequestContext>() .UseScopedHandler
private readonly IdentityUserManager _userManager;
public EmployeeNumberGrantHandler(IdentityUserManager userManager)
{
_userManager = userManager;
}
public async ValueTask HandleAsync(OpenIddictServerEvents.HandleTokenRequestContext context)
{
try
{
if (!string.Equals(context.Request.GrantType, "employee_number", StringComparison.Ordinal))
return ;
var empNo = context.Request["employee_number"]?.ToString();
var ts = context.Request["timestamp"]?.ToString();
var signature = context.Request["signature"]?.ToString();
if (string.IsNullOrEmpty(empNo) || string.IsNullOrEmpty(ts) || string.IsNullOrEmpty(signature))
{
context.Reject(OpenIddictConstants.Errors.InvalidRequest, "Missing parameters.");
return ;
}
// 1. 检查时间戳有效性
if (!long.TryParse(ts, out var ticks) ||
DateTime.UtcNow - new DateTime(ticks, DateTimeKind.Utc) > TimeSpan.FromMinutes(5))
{
context.Reject(OpenIddictConstants.Errors.InvalidGrant, "Expired timestamp.");
return ;
}
// 2. 验证签名
var raw = $"{empNo}:{ts}";
if (!VerifySignature(raw, signature, "SuperSecretSharedKey123!"))
{
context.Reject(OpenIddictConstants.Errors.InvalidGrant, "Invalid signature.");
return ;
}
// 3. 查找用户
var user = await _userManager.FindByNameAsync(empNo);
if (user == null)
{
context.Reject(OpenIddictConstants.Errors.InvalidGrant, "User not found.");
return;
}
// 4. 创建 ClaimsIdentity
var identity = new ClaimsIdentity(
TokenValidationParameters.DefaultAuthenticationType,
OpenIddictConstants.Claims.Name,
OpenIddictConstants.Claims.Role);
// subject(必须)
var subject = new Claim(OpenIddictConstants.Claims.Subject, user.Id.ToString());
subject.SetDestinations(OpenIddictConstants.Destinations.AccessToken,
OpenIddictConstants.Destinations.IdentityToken);
identity.AddClaim(subject);
// 用户名
var name = new Claim(OpenIddictConstants.Claims.Name, user.UserName ?? empNo);
name.SetDestinations(OpenIddictConstants.Destinations.AccessToken,
OpenIddictConstants.Destinations.IdentityToken);
identity.AddClaim(name);
// 工号
var empNoClaim = new Claim("employee_number", empNo);
empNoClaim.SetDestinations(OpenIddictConstants.Destinations.AccessToken,
OpenIddictConstants.Destinations.IdentityToken);
identity.AddClaim(empNoClaim);
// 5. 创建 principal
var principal = new ClaimsPrincipal(identity);
// 给 token 添加 scopes(至少 openid/profile,客户端必须要请求)
principal.SetScopes(new[]
{
OpenIddictConstants.Scopes.OpenId,
OpenIddictConstants.Scopes.Profile,
OpenIddictConstants.Scopes.Email,
OpenIddictConstants.Scopes.Roles
}.Intersect(context.Request.GetScopes()));
// 可以给 access_token 附加 API 资源
principal.SetResources("resource_server");
context.Principal = principal;
context.SignIn(principal);
context.HandleRequest();
}
catch (Exception ex)
{
context.Reject(OpenIddictConstants.Errors.InvalidGrant, ex.Message);
return ;
}
}
private static bool VerifySignature(string raw, string signature, string secretKey)
{
using var hmac = new System.Security.Cryptography.HMACSHA256(System.Text.Encoding.UTF8.GetBytes(secretKey));
var hash = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(raw));
var expected = Convert.ToBase64String(hash);
return expected == signature;
}
}`
Volo.Abp.AspNetCore.Mvc, Version=8.1.0.0
hi Can‘t reproduce this in a new template project. it seems in single-layer project the Volo.Abp.AspNetCore.Mvc.dll still references to Microsoft.AspNetCore.Mvc.Versioning
I 'v already cheked this pots. it doesn't work.
Hi, I Have tried all the setps:
Remove all migration files
Remove CPA/Migrations
Update DbContext:
Re-create the migration file.
Delete database
update-database
.still get the same error. and the menu doesn't show after login.need to refresh the page.
Thank u liangshiwei