/// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="next">Next middleware.</param>
 /// <param name="jwtAuthorizationOptions">Authorization options.</param>
 public GatewayAuthorizationMiddleware(
     RequestDelegate next,
     GatewayJwtAuthorizationOptions jwtAuthorizationOptions)
 {
     _next = Check.NotNull(next, nameof(next));
     _jwtAuthorizationOptions = Check.NotNull(jwtAuthorizationOptions, nameof(jwtAuthorizationOptions));
 }
示例#2
0
        /// <summary>
        /// Add gateway authentication middleware to request pipeline.
        /// </summary>
        /// <param name="app"><see cref="IApplicationBuilder"/> where middleware is added.</param>
        /// <param name="configuration">Configuration from which the options are loaded.
        /// Configuration must contains GatewayJwtAuthorization section.</param>
        /// <exception cref="InvalidOperationException">
        /// When `GatewayJwtAuthorization` section is missing in configuration.
        /// </exception>
        public static IApplicationBuilder UseGatewayJwtAuthorization(
            this IApplicationBuilder app,
            IConfiguration configuration)
        {
            GatewayJwtAuthorizationOptions option = configuration.GetSection <GatewayJwtAuthorizationOptions>();

            if (option is null)
            {
                throw new InvalidOperationException(
                          string.Format(Properties.Resources.OptionMissingSection,
                                        Helpers.GetSectionName <GatewayJwtAuthorizationOptions>()));
            }

            return(app.UseMiddleware <GatewayAuthorizationMiddleware>(option));
        }