Configuring ServiceStack 8 to work with OpenIdConnect

In my ServiceStack 8 application using ASP.Net Identity configured for OpenIdConnect like so in program.cs:

builder.Services.AddAuthentication(options =>
{
    options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
    options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; // Add this line
})
.AddCookie()
.AddOpenIdConnect(options =>
{
    options.MetadataAddress = "https://cognito-idp.{yourAwsRegion}.amazonaws.com/{yourUserPoolId}/.well-known/openid-configuration";
    options.Authority = $"https://{yourCognitoDomain}.auth.{yourAwsRegion}.amazoncognito.com";
    options.ClientId = clientId;
    options.ResponseType = OpenIdConnectResponseType.Code;
    options.CallbackPath = "/signin-oidc";
    options.SaveTokens = true;
    options.Scope.Add("email");
    options.Scope.Add("openid");
    options.Scope.Add("phone");
    options.Scope.Add("profile");

    options.TokenValidationParameters = new TokenValidationParameters
    {
        ValidateIssuer = true,
        ValidIssuer = $"https://cognito-idp.{yourAwsRegion}.amazonaws.com/{yourUserPoolId}",
        ValidateAudience = true,
        ValidAudience = clientId,
        ValidateLifetime = true,
        NameClaimType = "name",
        RoleClaimType = "cognito:groups"
    };
});
services.AddAuthorization();

...


app.UseAuthentication();
app.UseAuthorization();

app.UseServiceStack(new AppHost(), options =>
{
    options.MapEndpoints(useSystemJson: UseSystemJson.Never);
});

app.MapGet("/yo", [Authorize] (HttpContext context) =>
{
    //this is just for testing auth.
    return $"Hello {context.User.Claims.Single(r=> r.Type == "name").Value}.  We see your email is: {context.User.Claims.Single(r => r.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress").Value}  !";
});

I also have this TypeFilter in the GenerateCrudServices to ensure that all CRUD DTO’s require authentication:

TypeFilter = (type, req) =>
{
    if (type.IsCrud())
    {
        type.AddAttribute(new Microsoft.AspNetCore.Authorization.AuthorizeAttribute()); 
    }

The authentication flow works as expected. When I request any of the CRUD endpoints via the browser, the redirect to the auth provider happens, the user logs in, and the redirect back to the app works, and the api resource is displayed in the browser. Even the indicated “test” endpoint called ‘yo’ works and displays the username and email of the user as returned from the auth provider.

It’s the logout that I have a problem with. When I call /auth/logout, I get the following error:

System.Exception: Error trying to resolve Service ‘SignInManager1' or one of its autowired dependencies. at ServiceStack.ContainerExtensions.Resolve[T](IResolver container) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Common/SimpleContainer.cs:line 123 at ServiceStack.Auth.IdentityAuthProvider2.LogoutAsync(IServiceBase
service, Authenticate request, CancellationToken token) in
/home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Extensions/Auth/IdentityAuthProvider.cs:line
34 at
ServiceStack.Auth.AuthenticateService.HandleLogoutAsync(Authenticate
request, IAuthProvider authProvider) in
/home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/Auth/AuthenticateService.cs:line
439 at ServiceStack.Auth.AuthenticateService.PostAsync(Authenticate
request) in
/home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/Auth/AuthenticateService.cs:line
276 at ServiceStack.Host.ServiceRunner`1.ExecuteAsync(IRequest req,
Object instance, TRequest requestDto) in
/home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/Host/ServiceRunner.cs:line
149

There is no SignInManager registered in my config. Do I need to register one?

What am I missing?

If using ASP.NET Identity Auth with ServiceStack, you always need to register the AuthFeature plugin, e.g:

public class ConfigureAuth : IHostingStartup
{
    public void Configure(IWebHostBuilder builder) => builder
      .ConfigureAppHost(appHost =>  {
          appHost.Plugins.Add(new AuthFeature(IdentityAuth.For<ApplicationUser>(
              // Configure ServiceStack's Integration with Identity Auth
              options => {
                  options.SessionFactory = () => new CustomUserSession();
                  options.CredentialsAuth();
              })
          ));
      });
}

For a working example of an ASP.NET Identity Auth integration, check out ServiceStack’s Identity Auth Templates, whose source code is maintained at:

https://github.com/NetCoreTemplates/

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật