Repository navigation
Move the HTTP authentication services to Web.Common - #943
Merged
Merged
Conversation
CookieAuthenticationService and ApiAuthenticationService were the last Grand.Business.* classes reading HttpContext. They do nothing but HTTP work (the customer cookie, SignInAsync/SignOutAsync, the Authorization header, AuthenticateAsync for the JWT schemes), so no explicit argument could replace the ambient read: they belong in the web layer. IGrandAuthenticationService stays in Business.Core, because ExternalAuthenticationService and plugins use it; only its cookie implementation and DI registration move. IApiAuthenticationService and ICookieOptionsFactory have no users outside Web, so the interfaces move with their implementations, which also takes Microsoft.AspNetCore.Http CookieOptions out of the Business.Core contracts. Everything the moved classes depend on is a Business.Core contract, so Web.Common does not gain a dependency on a Business implementation. The JwtBearerAuthenticationService tests that lived in ApiAuthenticationServiceTests stay in Grand.Business.Authentication.Tests as JwtBearerAuthenticationServiceTests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the explicit-context work in Business (after #930–#942)
Type: feature
Issue
After #941 no
Grand.Business.*service readsIContextAccessor, but two still read the HTTP request directly:CookieAuthenticationServiceandApiAuthenticationServiceinGrand.Business.AuthenticationinjectIHttpContextAccessor. Their whole job is HTTP: the customer cookie,SignInAsync/SignOutAsync, theAuthorizationheader,AuthenticateAsyncfor the JWT schemes. No explicit argument could replace that read, so they are in the wrong layer.Reproduce:
grep -rln -E 'IContextAccessor|IHttpContextAccessor|HttpContext\b' src/Business --include=*.cs | grep -v Startuplists both files.Solution
CookieAuthenticationService,ApiAuthenticationServiceandCookieOptionsFactorymove toGrand.Web.Common/Security/Authentication(namespaceGrand.Web.Common.Security.Authentication), and their DI registrations move fromGrand.Business.Authentication'sStartupApplicationtoGrand.Web.Common's.IGrandAuthenticationServicestays inGrand.Business.Core:ExternalAuthenticationServiceand plugins use it. Only its cookie implementation moves.IApiAuthenticationServiceandICookieOptionsFactoryhave no users outside Web (the resolvers, theme contexts,CommonController), so they move with their implementations. This also takesMicrosoft.AspNetCore.Http.CookieOptionsout of the Business.Core contracts.Grand.Web.Commongains no dependency on a Business implementation (compatible with Move the business layer implementations to the hosts #772).Grand.Web.Common.Tests/Security/Authentication. TheJwtBearerAuthenticationServicetests that lived insideApiAuthenticationServiceTestsstay inGrand.Business.Authentication.TestsasJwtBearerAuthenticationServiceTests.The grep above now returns nothing.
Grand.Business.Authenticationstill depends on ASP.NET Core (itsStartupApplicationregisters the JWT and cookie schemes,JwtBearer*Serviceuses JWT types); that is a separate step.Breaking changes
CookieAuthenticationService,ApiAuthenticationServiceandCookieOptionsFactory:Grand.Business.Authentication.Services→Grand.Web.Common.Security.Authentication; they also move to theGrand.Web.Commonassembly. External subclasses ofCookieAuthenticationService(it hasvirtualmembers) must update the namespace and reference.IApiAuthenticationServiceandICookieOptionsFactory:Grand.Business.Core.Interfaces.Authentication→Grand.Web.Common.Security.Authentication. A theme or plugin deriving fromThemeContextBaseor injectingICookieOptionsFactoryupdates itsusingand is rebuilt.IGrandAuthenticationServicedo not change. No in-repo plugin implements or subclasses the moved types.IGrandAuthenticationService,ICookieOptionsFactoryandIApiAuthenticationServiceare now registered byGrand.Web.Common(startupPriority0) instead ofGrand.Business.Authentication(Priority100). A plugin or module withPriority1–100 that registers its own implementation of one of them used to be overridden by the core one; now its implementation wins. No in-repo plugin or module registers these services.Testing
Automated: the solution builds with no new warnings.
Grand.Business.Authentication.Tests(295),Grand.Web.Common.Tests(538) andGrand.Web.Tests(152) pass. Test count across the two auth/web-common projects is unchanged (679 before and after).Manual (not run yet):
ICookieOptionsFactory)./api/...withAuthorization: Bearer <token>→ 200; call without a token → 401.