Ejemplo n.º 1
0
        public void ConfigureServices(IServiceCollection services)
        {
            ConfigureAuth(services);
            var machineKeyConfig = new XmlMachineKeyConfig(File.OpenRead("machine_config.xml"));
            MachineKeyDataProtectionOptions machinekeyOptions = new MachineKeyDataProtectionOptions
            {
                MachineKey = new MachineKey(machineKeyConfig)
            };
            MachineKeyDataProtectionProvider machineKeyDataProtectionProvider = new MachineKeyDataProtectionProvider(machinekeyOptions);
            MachineKeyDataProtector          machineKeyDataProtector          = new MachineKeyDataProtector(machinekeyOptions.MachineKey);

            IDataProtector dataProtector = machineKeyDataProtector.CreateProtector("Microsoft.Owin.Security.OAuth", "Access_Token", "v1");

            services.AddAuthentication(options =>
            {
                options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddOAuthValidation(option =>
            {
                option.DataProtectionProvider = machineKeyDataProtectionProvider;
                option.AccessTokenFormat      = new OwinTicketDataFormat(new OwinTicketSerializer(3), dataProtector);
            })
            .AddOpenIdConnectServer(options => {
                options.ProviderType                = typeof(AuthorizationProvider);
                options.TokenEndpointPath           = "/token";
                options.AllowInsecureHttp           = false;
                options.ApplicationCanDisplayErrors = true;
                options.AccessTokenLifetime         = TimeSpan.FromHours(24);
                options.RefreshTokenLifetime        = TimeSpan.FromDays(30);
                options.AccessTokenFormat           = new OwinTicketDataFormat(new OwinTicketSerializer(3), dataProtector);
                options.RefreshTokenFormat          = new OwinTicketDataFormat(new OwinTicketSerializer(3), dataProtector);
            });;
            services.AddMvc();
        }
Ejemplo n.º 2
0
        public static IMachineKeyDataProtectionBuilder AddMachineKeyDataProtection(this IServiceCollection services, Action <MachineKeyDataProtectionOptions> setupAction)
        {
            MachineKeyDataProtectionOptions options = new MachineKeyDataProtectionOptions();

            if (setupAction != null)
            {
                setupAction.Invoke(options);
            }
            MachineKeyDataProtectionProvider machineKeyDataProtectionProvider = new MachineKeyDataProtectionProvider(options);

            services.TryAddSingleton <IDataProtectionProvider>(machineKeyDataProtectionProvider);
            return(new MachineKeyDataProtectionBuilder
            {
                Options = options
            });
        }
Ejemplo n.º 3
0
        public AccountManager(IUserStore <User> store) : base(store)
        {
            accountStore  = store as AccountStore;
            UserValidator = new UserValidator <User>(this)
            {
                AllowOnlyAlphanumericUserNames = true,
                RequireUniqueEmail             = true
            };

            PasswordValidator = new PasswordValidator
            {
                RequiredLength = 6
            };

            MachineKeyDataProtectionProvider dataProtectionProvider = new MachineKeyDataProtectionProvider();

            this.UserTokenProvider = new DataProtectorTokenProvider <User, string>(dataProtectionProvider.Create("Email Notification"))
            {
                TokenLifespan = TimeSpan.FromHours(6)
            };
        }