@@ -122,6 +122,20 @@ public async Task ServicesWithDefaultSignOutMethodsTest()
122
122
await Assert . ThrowsAsync < InvalidOperationException > ( ( ) => context . SignInAsync ( new ClaimsPrincipal ( ) ) ) ;
123
123
}
124
124
125
+ [ Fact ]
126
+ public async Task ServicesWithDefaultForbidMethod_CallsForbidMethod ( )
127
+ {
128
+ var services = new ServiceCollection ( ) . AddOptions ( ) . AddAuthenticationCore ( o =>
129
+ {
130
+ o . AddScheme < ForbidHandler > ( "forbid" , "whatever" ) ;
131
+ o . DefaultForbidScheme = "forbid" ;
132
+ } ) . BuildServiceProvider ( ) ;
133
+ var context = new DefaultHttpContext ( ) ;
134
+ context . RequestServices = services ;
135
+
136
+ await context . ForbidAsync ( ) ;
137
+ }
138
+
125
139
126
140
private class BaseHandler : IAuthenticationHandler
127
141
{
@@ -245,5 +259,43 @@ public Task SignOutAsync(AuthenticationProperties properties)
245
259
}
246
260
}
247
261
262
+ private class ForbidHandler : IAuthenticationHandler , IAuthenticationRequestHandler , IAuthenticationSignInHandler , IAuthenticationSignOutHandler
263
+ {
264
+ public Task < AuthenticateResult > AuthenticateAsync ( )
265
+ {
266
+ throw new NotImplementedException ( ) ;
267
+ }
268
+
269
+ public Task ChallengeAsync ( AuthenticationProperties properties )
270
+ {
271
+ throw new NotImplementedException ( ) ;
272
+ }
273
+
274
+ public Task ForbidAsync ( AuthenticationProperties properties )
275
+ {
276
+ return Task . FromResult ( 0 ) ;
277
+ }
278
+
279
+ public Task < bool > HandleRequestAsync ( )
280
+ {
281
+ throw new NotImplementedException ( ) ;
282
+ }
283
+
284
+ public Task InitializeAsync ( AuthenticationScheme scheme , HttpContext context )
285
+ {
286
+ return Task . FromResult ( 0 ) ;
287
+ }
288
+
289
+ public Task SignInAsync ( ClaimsPrincipal user , AuthenticationProperties properties )
290
+ {
291
+ throw new NotImplementedException ( ) ;
292
+ }
293
+
294
+ public Task SignOutAsync ( AuthenticationProperties properties )
295
+ {
296
+ throw new NotImplementedException ( ) ;
297
+ }
298
+ }
299
+
248
300
}
249
301
}
0 commit comments