Add to all projects where hangfire is installed
The specified token is invalid
what's is the full error message
Hi,
It works for me
context.Services.AddAuthentication()
.AddOpenIdConnect("AzureOpenId", "Azure AD OpenId", options =>
{
options.Authority = "https://login.microsoftonline.com/" + configuration["AzureAd:TenantId"] + "/v2.0/";
options.ClientId = configuration["AzureAd:ClientId"];
options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
options.CallbackPath = configuration["AzureAd:CallbackPath"];
options.ClientSecret = configuration["AzureAd:ClientSecret"];
options.RequireHttpsMetadata = false;
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.Scope.Add("email");
options.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "sub");
});
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(LogoutModel))]
public class MyLoginOutModel : LogoutModel
{
public override async Task<IActionResult> OnGetAsync()
{
if (CurrentUser.IsAuthenticated)
{
await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext
{
Identity = IdentitySecurityLogIdentityConsts.Identity,
Action = IdentitySecurityLogActionConsts.Logout
});
}
//
await SignInManager.SignOutAsync();
await HttpContext.SignOutAsync(ConfirmUserModel.ConfirmUserScheme);
await HttpContext.SignOutAsync(ChangePasswordModel.ChangePasswordScheme);
return SignOut("AzureOpenId");
}
}
Hi,
After my check, This is the default behavior.
If you want to logout from Azure Id, You need to redirect manually.
For example:
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(LogoutModel))]
public class MyLoginOutModel : LogoutModel
{
public override async Task<IActionResult> OnGetAsync()
{
if (CurrentUser.IsAuthenticated)
{
await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext
{
Identity = IdentitySecurityLogIdentityConsts.Identity,
Action = IdentitySecurityLogActionConsts.Logout
});
}
//
await SignInManager.SignOutAsync();
await HttpContext.SignOutAsync(ConfirmUserModel.ConfirmUserScheme);
await HttpContext.SignOutAsync(ChangePasswordModel.ChangePasswordScheme);
// redirect to azure id
return Redirect("https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri=https://localhost:44382/Account/Login");
}
}
your ticket was refunded
It's a problem, I will enhance it in the next version
it's okay
Hi,
How do I reproduce the problem?
Could you share a simple example with me? I will check it. thx my email is shiwei.liang@volosoft.com
Hi,
This is a known problem, we will fix it in the next patch version,
This is a temporary solution
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(IBackgroundWorkerManager), typeof(HangfireBackgroundWorkerManager))]
public class MyHangfireBackgroundWorkerManager: HangfireBackgroundWorkerManager
{
public MyHangfireBackgroundWorkerManager(IServiceProvider serviceProvider) : base(serviceProvider)
{
}
protected override string GetCron(int period)
{
var time = TimeSpan.FromMilliseconds(period);
string cron;
if (time.TotalSeconds <= 59)
{
cron = $"*/{time.TotalSeconds} * * * * *";
}
else if (time.TotalMinutes <= 59)
{
cron = $"*/{time.TotalMinutes} * * * *";
}
else if (time.TotalHours <= 23)
{
cron = $"0 */{time.TotalHours} * * *";
}
else if(time.TotalDays <= 31)
{
cron = $"0 0 0 1/{time.TotalDays} * *";
}
else
{
throw new AbpException(
$"Cannot convert period: {period} to cron expression, use HangfireBackgroundWorkerBase to define worker");
}
return cron;
}
}