No authentication handler is registered for the scheme 'OpenIdConnect'

Product: PowerShell Universal
Version: 3.7.9

If I want to upgrade to a newer version of PowerShell Universal the Admin Dashboard cannot
be opened. It flickers. If I look at the log I see the following error Message:

2023-02-18 13:33:46.124 +01:00 [ERR] An unhandled exception has occurred while executing the request.
System.InvalidOperationException: No authentication handler is registered for the scheme 'OpenIdConnect'. The registered schemes are: Identity.External, Cookies, Bearer, Deny. Did you forget to call AddAuthentication().Add[SomeAuthHandler]("OpenIdConnect",...)?
   at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
   at Microsoft.AspNetCore.Authorization.Policy.PolicyEvaluator.AuthenticateAsync(AuthorizationPolicy policy, HttpContext context)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at PowerShellUniversal.FeatureMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) in C:\actions-runner\_work\universal\universal\src\Universal.Server\Middleware\FeatureMiddleware.cs:line 42
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at PowerShellUniversal.DisallowedModeMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) in C:\actions-runner\_work\universal\universal\src\Universal.Server\Middleware\ModeMiddleware.cs:line 46
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at Universal.Server.Middleware.RoutingMiddleware.Invoke(HttpContext httpContext, IPolicyEvaluator policyEvaluator) in C:\actions-runner\_work\universal\universal\src\Universal.Server\Middleware\RoutingMiddleware.cs:line 172
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Universal.Server.Middleware.SwaggerAuthenticationMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) in C:\actions-runner\_work\universal\universal\src\Universal.Server\Middleware\SwaggerAuthMiddleware.cs:line 35
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at AspNetCoreRateLimit.RateLimitMiddleware`1.Invoke(HttpContext context) in C:\actions-runner\_work\universal\universal\src\AspNetCoreRateLimit\Middleware\RateLimitMiddleware.cs:line 109
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)

my Authentication.ps1 looks like this

Set-PSUAuthenticationMethod -Type "Form" -ScriptBlock {
param(
        [PSCredential]$Credential
    )

    #
    #   You can call whatever cmdlets you like to conduct authentication here.
    #   Just make sure to return the $Result with the Success property set to $true
    #

    $Result = [Security.AuthenticationResult]::new()
    if ($Credential.UserName -eq 'Admin')
    {
        $Result.UserName = 'Admin'
        $Result.Success = $true
    } 

    $Result
}

Set-PSUAuthenticationMethod -Type "OpenIDConnect" -CallbackPath "/auth/signin-oidc" -ClientId "xxx" -ClientSecret "xxx" -Authority "https://login.microsoftonline.com/xxx"

Is Set-PSUAuthenticationMethod not supported in the newer versions. Should I configure it in the appsettings.json.

What is the cause of this problem @adam?

I had this issue just the other day when PSU somehow nuked my Licenses.ps1 file.

Disabling OIDC in Appsettings temporarely, allowed me to get in and upload a new license - alternativly restore the Licenses.ps1 file in the configurations repository.

Hope it helps.

Thank you. That was the problem. I had an expired license inside of PSU. I imported a new one and that works. It is a bit strange that if a license is expired the product is still showing licensed.

1 Like

@adam Maybe the process of handling expired or dissappeared licenses could be a bit more graceful :sweat_smile:

We’ve done some work with this in 3.8. Some changes:

  • When a license is expiring (30 days out), it will show a warning in the admin console
  • When the license expires, we do not disable any features for 30 days and will display an error in the admin console
  • We’ve added License Expiring and License Expired triggers that will fire at the same times as above to allow for notifications outside of PSU
2 Likes

Thank you @adam. That sounds great.