@@ -67,26 +67,17 @@ public static IServiceCollection AddUltimateAuthServer(this IServiceCollection s
6767 return services ;
6868 }
6969
70- public static IServiceCollection AddUltimateAuthResourceApi ( this IServiceCollection services , Action < UAuthServerOptions > ? configure = null )
70+ public static IServiceCollection AddUltimateAuthResourceApi ( this IServiceCollection services , Action < UAuthResourceApiOptions > ? configure = null )
7171 {
7272 ArgumentNullException . ThrowIfNull ( services ) ;
7373 services . AddUltimateAuth ( ) ;
7474
75- //AddUsersInternal(services);
76- //AddCredentialsInternal(services);
77- //AddAuthorizationInternal(services);
78- //AddUltimateAuthPolicies(services);
79-
80- services . AddOptions < UAuthServerOptions > ( )
75+ services . AddOptions < UAuthResourceApiOptions > ( )
8176 . Configure ( options =>
8277 {
8378 configure ? . Invoke ( options ) ;
8479 } )
85- . BindConfiguration ( "UltimateAuth:Server" )
86- . PostConfigure ( options =>
87- {
88- options . Endpoints . Authentication = false ;
89- } ) ;
80+ . BindConfiguration ( "UltimateAuth:ResourceApi" ) ;
9081
9182 services . AddUltimateAuthResourceInternal ( ) ;
9283
@@ -126,7 +117,7 @@ private static IServiceCollection AddUltimateAuthServerInternal(this IServiceCol
126117 services . TryAddEnumerable ( ServiceDescriptor . Singleton < IAuthorityInvariant , InvalidOrRevokedSessionInvariant > ( ) ) ;
127118 services . TryAddEnumerable ( ServiceDescriptor . Singleton < IAuthorityInvariant , TenantResolvedInvariant > ( ) ) ;
128119
129- // EVENTS
120+ // Events
130121 services . AddSingleton ( sp =>
131122 {
132123 var options = sp . GetRequiredService < IOptions < UAuthServerOptions > > ( ) . Value ;
@@ -247,9 +238,7 @@ private static IServiceCollection AddUltimateAuthServerInternal(this IServiceCol
247238
248239 services . TryAddScoped < IHubCapabilities , HubCapabilities > ( ) ;
249240
250- // -----------------------------
251- // ENDPOINTS
252- // -----------------------------
241+ // Endpoints
253242 services . TryAddScoped < AuthFlowEndpointFilter > ( ) ;
254243 services . TryAddSingleton < IAuthEndpointRegistrar , UAuthEndpointRegistrar > ( ) ;
255244
@@ -260,9 +249,7 @@ private static IServiceCollection AddUltimateAuthServerInternal(this IServiceCol
260249 services . TryAddScoped < IRefreshEndpointHandler , RefreshEndpointHandler > ( ) ;
261250 services . TryAddScoped < IPkceEndpointHandler , PkceEndpointHandler > ( ) ;
262251
263- // ------------------------------
264- // ASP.NET CORE INTEGRATION
265- // ------------------------------
252+ // ASP.NET Core Integration
266253 services . AddAuthentication ( ) ;
267254
268255 services . PostConfigureAll < AuthenticationOptions > ( options =>
@@ -389,17 +376,16 @@ public static IServiceCollection AddUAuthHub(this IServiceCollection services, A
389376 return services ;
390377 }
391378
392- // TODO: This is not true, need to build true pipeline for ResourceApi.
393379 private static IServiceCollection AddUltimateAuthResourceInternal ( this IServiceCollection services )
394380 {
381+ // Resource API Specific
395382 services . AddSingleton < IUAuthRuntimeMarker , ResourceRuntimeMarker > ( ) ;
396383
397384 services . AddScoped < ISessionValidator , RemoteSessionValidator > ( ) ;
398385 services . AddScoped < IUserAccessor < UserKey > , ResourceUserAccessor < UserKey > > ( ) ;
399386 services . AddScoped < IAuthContextFactory , ResourceAuthContextFactory > ( ) ;
400-
401- services . TryAddScoped < IRefreshTokenValidator , UAuthRefreshTokenValidator > ( ) ;
402387
388+ // Server & Resource API Shared
403389 services . TryAddScoped < IUserAccessor , UserAccessorBridge > ( ) ;
404390 services . TryAddScoped < ISessionContextAccessor , SessionContextAccessor > ( ) ;
405391 services . TryAddScoped < ICurrentUser , HttpContextCurrentUser > ( ) ;
@@ -413,14 +399,12 @@ private static IServiceCollection AddUltimateAuthResourceInternal(this IServiceC
413399
414400 services . TryAddScoped < ITransportCredentialResolver , TransportCredentialResolver > ( ) ;
415401 services . TryAddScoped < IDeviceContextFactory , DeviceContextFactory > ( ) ;
416- services . TryAddScoped < IAuthStateSnapshotFactory , AuthStateSnapshotFactory > ( ) ;
417402 services . TryAddScoped < IPrimaryCredentialResolver , PrimaryCredentialResolver > ( ) ;
418403 services . TryAddScoped < IDeviceResolver , DeviceResolver > ( ) ;
419404
420405 services . TryAddSingleton < IClock , CodeBeam . UltimateAuth . Server . Infrastructure . SystemClock > ( ) ;
421406
422- services . AddHttpContextAccessor ( ) ;
423- services . AddAuthentication ( ) ;
407+
424408
425409 services . TryAddScoped < ITenantResolver , UAuthTenantResolver > ( ) ;
426410 services . TryAddSingleton < ITenantIdResolver > ( sp =>
@@ -446,37 +430,24 @@ private static IServiceCollection AddUltimateAuthResourceInternal(this IServiceC
446430 } ;
447431 } ) ;
448432
449- services . AddAuthentication ( ) ;
450-
451- services . PostConfigureAll < AuthenticationOptions > ( options =>
433+ // ASP.NET Core Integration
434+ services . AddHttpContextAccessor ( ) ;
435+ services . AddAuthentication ( options =>
452436 {
453- options . DefaultAuthenticateScheme ??= UAuthConstants . SchemeDefaults . GlobalScheme ;
454- options . DefaultSignInScheme ??= UAuthConstants . SchemeDefaults . GlobalScheme ;
455- options . DefaultChallengeScheme ??= UAuthConstants . SchemeDefaults . GlobalScheme ;
456- } ) ;
457-
458- services . AddAuthentication ( ) . AddUAuthResourceApi ( ) ;
437+ options . DefaultAuthenticateScheme = UAuthConstants . SchemeDefaults . GlobalScheme ;
438+ options . DefaultChallengeScheme = UAuthConstants . SchemeDefaults . GlobalScheme ;
439+ } )
440+ . AddUAuthResourceApi ( ) ;
459441 services . AddAuthorization ( ) ;
460442
461- services . TryAddSingleton < IRefreshTokenStoreFactory , NotSupportedRefreshTokenStoreFactory > ( ) ;
462- services . TryAddSingleton < IUserRoleStoreFactory , NotSupportedUserRoleStoreFactory > ( ) ;
463- services . TryAddSingleton < IUAuthPasswordHasher , NotSupportedPasswordHasher > ( ) ;
464- services . TryAddSingleton < IIdentifierValidator , NoOpIdentifierValidator > ( ) ;
465- services . TryAddSingleton < IAccessPolicyProvider , AllowAllAccessPolicyProvider > ( ) ;
466- services . TryAddScoped < IUserClaimsProvider , NoOpUserClaimsProvider > ( ) ;
467- services . TryAddSingleton < ITokenHasher , NoOpTokenHasher > ( ) ;
468- services . TryAddScoped < IPrimaryUserIdentifierProvider , NoOpPrimaryUserIdentifierProvider > ( ) ;
469- services . TryAddScoped < IUserProfileSnapshotProvider , NoOpUserProfileSnapshotProvider > ( ) ;
470- services . TryAddScoped < IUserLifecycleSnapshotProvider , NoOpUserLifecycleSnapshotProvider > ( ) ;
471-
472- //services.PostConfigureAll<AuthenticationOptions>(options =>
473- //{
474- // options.DefaultAuthenticateScheme ??= UAuthConstants.SchemeDefaults.GlobalScheme;
475- //});
476-
477- services . AddHttpClient < ISessionValidator , RemoteSessionValidator > ( client =>
443+ services . AddHttpClient < ISessionValidator , RemoteSessionValidator > ( ( sp , client ) =>
478444 {
479- client . BaseAddress = new Uri ( "https://localhost:6110" ) ; // Auth Server
445+ var opts = sp . GetRequiredService < IOptions < UAuthResourceApiOptions > > ( ) . Value ;
446+
447+ if ( string . IsNullOrWhiteSpace ( opts . UAuthHubBaseUrl ) )
448+ throw new InvalidOperationException ( "UAuthHubBaseUrl is not configured. Add it via UAuthResourceApiOptions." ) ;
449+
450+ client . BaseAddress = new Uri ( opts . UAuthHubBaseUrl ) ;
480451 } ) ;
481452
482453 return services ;
0 commit comments