IdentityServer / IdentityServer4.AccessTokenValidation

IdentityServer Access Token Validation for ASP.NET Core
Apache License 2.0
544 stars 214 forks source link

Expose OAuth2IntrospectionEvents in IdentityServerAuthenticationOptions #115

Closed terry-delph closed 5 years ago

terry-delph commented 5 years ago

Hi,

It would be useful to expose the OAuth2Introspections events (OnCreatingTicket and OnAuthenticationFailed) in the IdentityServerAuthenticationOptions. This would then follow the same pattern as allowing the JwtBearerEvents to be exposed.

Use Cases:

Notes: I have heard of people saying that a middleware can be used to enrich the claims but the middleware after "UseAuthentication", all execute before the ClaimsIdentity is created, therefore the only option after that is using an ActionFilter to augment the claims. The Authentication handlers only execute when that scheme is called upon when it reaches the MVC middleware, which is too late. My project has 2 schemes.

Presumed Code Changes:

public class IdentityServerAuthenticationOptions : AuthenticationSchemeOptions
{
        Other code removed for brevity...

        /// <summary>
        /// Events for IntrospectionEvents
        /// </summary>
        public OAuth2IntrospectionEvents IntrospectionEvents { get; set; } =  new OAuth2IntrospectionEvents();

        internal void ConfigureIntrospection(OAuth2IntrospectionOptions introspectionOptions)
        {
            Other Code removed for brevity

            introspectionOptions.Events = new OAuth2IntrospectionEvents
            {
                OnAuthenticationFailed = e => IntrospectionEvents.OnAuthenticationFailed(e),
                OnCreatingTicket = e => IntrospectionEvents.OnCreatingTicket(e)
            };
        }
}

Many thanks

leastprivilege commented 5 years ago

OK. Send a PR please.