.Net Authentication Flashcards

1
Q

What components does authentication in .net consist of?

A

Authentication middleware
uses IAuthenticationService
uses Authentication handlers

The authentication service uses registered authentication handlers to complete authentication-related actions, e.g. Authenticate, Challenge, Forbid, SignIn, SignOut

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is authentication schema?

A

The registered authentication handler and its configuration options are called “schema”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to specify the authentication scheme?

A

You can do it when registering authentication service.

And there are two ways:
- using specific schema-specific extensions, e.g. AddCookie, AddJwtBearer
- using AddScheme on AuthenticationBuilder

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to register authentication service?

A

By calling AddAuthentication extension method on IServiceCollection. It returns AuthenticationBuilder. One of the overloads allows specifying the default scheme, one allows configuring AuthenticationOptions itself.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to use AddScheme on AuthenticationBuilder?

A

The method allows to create a schema with a particular name, options, handler, and configure options.

As you can see below, options are inheriter of AuthenticationSchemeOptions, handler is inheriter of AuthenticationHandler<TOptions></TOptions>

AuthenticationBuilder.AddScheme<TOptions,THandler> (string schemeName, Action<TOptions>? configureOptions) where TOptions : AuthenticationSchemeOptions, new() where THandler: AuthenticationHandler<TOptions>;</TOptions></TOptions>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly