Beispiel #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();
        }
Beispiel #2
0
        public AccountService(IUserStore <Account> store) : base(store)
        {
            var machineKeyDataProtector = new MachineKeyDataProtector("ResetPasswordPurpose");

            this.UserTokenProvider = new DataProtectorTokenProvider <Account>(machineKeyDataProtector)
            {
                TokenLifespan = TimeSpan.FromHours(24),
            };

            //config validator for user model
            this.UserValidator = new UserValidator <Account>(this)
            {
                RequireUniqueEmail             = false,
                AllowOnlyAlphanumericUserNames = false
            };
        }
Beispiel #3
0
 /// <summary>
 /// Initializes the <see cref="TokenContext"/> class.
 /// </summary>
 static TokenContext()
 {
     _cache     = CacheManager.Instance;
     _protector = new MachineKeyDataProtector(new[] { typeof(TokenContext).FullName });
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SdkContext"/> class.
 /// </summary>
 /// <param name="cache">An instance of <see cref="ICacheManager"/> used for caching tokens.</param>
 public SdkContext(ICacheManager cache)
 {
     _cache     = cache;
     _protector = new MachineKeyDataProtector(new[] { typeof(DistributedTokenCache).FullName });
 }