Ejemplo n.º 1
0
        public void Scope_TryAdd_RealValues_Test(string expected, string origin, params string[] values)
        {
            var test = new ScopeTester();

            test.Scope.Add(origin.ToString());
            Debug.WriteLine(test.ToString());

            QQConnectScopes.TryAdd(test.Scope, values);
            Debug.WriteLine(test.ToString());

            Assert.Equal(expected, test.ToString());
        }
Ejemplo n.º 2
0
        public void Scope_TryAdd_One_Test()
        {
            var test = new ScopeTester();

            Assert.Empty(test.Scope);

            test.Scope.Add("1");
            Assert.Equal("1", test.ToString());

            QQConnectScopes.TryAdd(test.Scope, "2".Split(","));
            Assert.Equal("1,2", test.ToString());

            QQConnectScopes.TryAdd(test.Scope, "3,4".Split(","));
            Assert.Equal("1,2,3,4", test.ToString());

            QQConnectScopes.TryAdd(test.Scope, "2,3,5,6".Split(","));
            Assert.Equal("1,2,3,4,5,6", test.ToString());
        }
Ejemplo n.º 3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlite(Configuration.GetConnectionString("DefaultConnection"),
                                                                   x => x.MigrationsAssembly("BlazorDemo.Server")));

            services.AddIdentity <AppUser, AppRole>()
            .AddEntityFrameworkStores <AppDbContext>()
            .AddUserManager <AppUserManager>()
            .AddSignInManager <SignInManager <AppUser> >()
            .AddDefaultTokenProviders();

            services.Configure <IdentityOptions>(options =>
            {
                // Password settings
                options.Password.RequireDigit           = false;
                options.Password.RequiredLength         = 6;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequireLowercase       = false;
                //options.Password.RequiredUniqueChars = 6;

                // Lockout settings
                options.Lockout.DefaultLockoutTimeSpan  = TimeSpan.FromMinutes(30);
                options.Lockout.MaxFailedAccessAttempts = 10;
                options.Lockout.AllowedForNewUsers      = true;

                // User settings
                options.User.RequireUniqueEmail = false;
            });

            services.AddAuthentication()
            .AddWeixinOpen(options =>
            {
                options.AppId      = Configuration["WeixinOpen:AppId"];
                options.AppSecret  = Configuration["WeixinOpen:AppSecret"];
                options.SaveTokens = true;
            })
            .AddWeixinAuth(options =>
            {
                options.AppId      = Configuration["WeixinAuth:AppId"];
                options.AppSecret  = Configuration["WeixinAuth:AppSecret"];
                options.SilentMode = false;     //不采用静默模式
                                                //options.SaveTokens = true;
            })
            .AddQQConnect(options =>
            {
                options.AppId  = Configuration["QQConnect:AppId"];
                options.AppKey = Configuration["QQConnect:AppKey"];
                //options.SaveTokens = true;

                QQConnectScopes.TryAdd(options.Scope,
                                       QQConnectScopes.get_user_info,
                                       QQConnectScopes.list_album,
                                       QQConnectScopes.upload_pic,
                                       QQConnectScopes.do_like);
            });

            services.AddTencentSms(options =>
            {
                options.SdkAppId = Configuration["TencentSms:SdkAppId"];
                options.AppKey   = Configuration["TencentSms:AppKey"];
            });

            services.Configure <ApiBehaviorOptions>(options =>
            {
                options.SuppressModelStateInvalidFilter = true;
            });

            services.ConfigureApplicationCookie(options =>
            {
                options.Cookie.HttpOnly          = false;
                options.Events.OnRedirectToLogin = context =>
                {
                    context.Response.StatusCode = 401;
                    return(Task.CompletedTask);
                };
            });

            //services.AddControllers().AddNewtonsoftJson();
            services.AddMvc().AddNewtonsoftJson();
            services.AddResponseCompression(opts =>
            {
                opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
                    new[] { "application/octet-stream" });
            });
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlite(Configuration.GetConnectionString("DefaultConnection"),
                                                                   x => x.MigrationsAssembly("Demo")));

            services.AddIdentity <AppUser, AppRole>()
            .AddEntityFrameworkStores <AppDbContext>()
            .AddUserManager <AppUserManager>()
            .AddSignInManager <SignInManager <AppUser> >()
            .AddDefaultTokenProviders();
            services.Configure <IdentityOptions>(options =>
            {
                options.Password = new PasswordOptions
                {
                    RequireLowercase       = false,
                    RequireUppercase       = false,
                    RequireNonAlphanumeric = false,
                    RequireDigit           = false
                };
                options.User.RequireUniqueEmail      = false;
                options.SignIn.RequireConfirmedEmail = false;

                options.SignIn.RequireConfirmedPhoneNumber = true;
            });
            services.ConfigureApplicationCookie(options =>
            {
                options.LoginPath        = "/Account/Login";
                options.LogoutPath       = "/Account/LogOff";
                options.AccessDeniedPath = "/Account/AccessDenied";
            });

            services.AddAuthentication()
            .AddWeixinOpen(options =>
            {
                options.AppId      = Configuration["WeixinOpen:AppId"];
                options.AppSecret  = Configuration["WeixinOpen:AppSecret"];
                options.SaveTokens = true;
            })
            .AddWeixinAuth(options =>
            {
                options.AppId      = Configuration["WeixinAuth:AppId"];
                options.AppSecret  = Configuration["WeixinAuth:AppSecret"];
                options.SilentMode = false;     //不采用静默模式
                                                //options.SaveTokens = true;
            })
            .AddQQConnect(options =>
            {
                options.AppId  = Configuration["QQConnect:AppId"];
                options.AppKey = Configuration["QQConnect:AppKey"];
                //options.SaveTokens = true;

                QQConnectScopes.TryAdd(options.Scope,
                                       QQConnectScopes.get_user_info,
                                       QQConnectScopes.list_album,
                                       QQConnectScopes.upload_pic,
                                       QQConnectScopes.do_like);
            });

            services.AddTencentSms(options =>
            {
                options.SdkAppId = Configuration["TencentSms:SdkAppId"];
                options.AppKey   = Configuration["TencentSms:AppKey"];
            });

            services.AddViewDivert();
            services.AddWeixinAccessToken(options =>
            {
                options.AppId     = Configuration["Weixin:AppId"];
                options.AppSecret = Configuration["Weixin:AppSecret"];
            });
            services.AddWeixinJssdk(options =>
            {
                options.AppId = Configuration["Weixin:AppId"];
            });
            services.AddScoped <IWeixinEventSink, WeixinEventSink>();
            IWeixinEventSink weixinEventSink = services.BuildServiceProvider().GetRequiredService <IWeixinEventSink>();

            services.AddWeixinWelcomePage(options =>
            {
                options.AppId          = Configuration["Weixin:AppId"];
                options.AppSecret      = Configuration["Weixin:AppSecret"];
                options.WebsiteToken   = Configuration["Weixin:WebsiteToken"];
                options.EncodingAESKey = Configuration["Weixin:EncodingAESKey"];
                options.Path           = "/wx";
                options.Events         = new WeixinMessageEvents()
                {
                    OnTextMessageReceived       = ctx => weixinEventSink.OnTextMessageReceived(ctx.Sender, ctx.Args),
                    OnLinkMessageReceived       = ctx => weixinEventSink.OnLinkMessageReceived(ctx.Sender, ctx.Args),
                    OnClickMenuEventReceived    = ctx => weixinEventSink.OnClickMenuEventReceived(ctx.Sender, ctx.Args),
                    OnImageMessageReceived      = ctx => weixinEventSink.OnImageMessageReceived(ctx.Sender, ctx.Args),
                    OnLocationEventReceived     = ctx => weixinEventSink.OnLocationEventReceived(ctx.Sender, ctx.Args),
                    OnLocationMessageReceived   = ctx => weixinEventSink.OnLocationMessageReceived(ctx.Sender, ctx.Args),
                    OnQrscanEventReceived       = ctx => weixinEventSink.OnQrscanEventReceived(ctx.Sender, ctx.Args),
                    OnSubscribeEventReceived    = ctx => weixinEventSink.OnSubscribeEventReceived(ctx.Sender, ctx.Args),
                    OnUnsubscribeEventReceived  = ctx => weixinEventSink.OnUnsubscribeEventReceived(ctx.Sender, ctx.Args),
                    OnVideoMessageReceived      = ctx => weixinEventSink.OnVideoMessageReceived(ctx.Sender, ctx.Args),
                    OnShortVideoMessageReceived = ctx => weixinEventSink.OnShortVideoMessageReceived(ctx.Sender, ctx.Args),
                    OnViewMenuEventReceived     = ctx => weixinEventSink.OnViewMenuEventReceived(ctx.Sender, ctx.Args),
                    OnVoiceMessageReceived      = ctx => weixinEventSink.OnVoiceMessageReceived(ctx.Sender, ctx.Args)
                };
            });

            services.AddControllersWithViews();
        }
Ejemplo n.º 5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlite(Configuration.GetConnectionString("DefaultConnection"),
                                                                   x => x.MigrationsAssembly("Demo.Shared")));

            services.AddIdentity <AppUser, AppRole>()
            .AddEntityFrameworkStores <AppDbContext>()
            .AddUserManager <AppUserManager>()
            .AddSignInManager <SignInManager <AppUser> >()
            .AddDefaultTokenProviders();
            services.Configure <IdentityOptions>(options =>
            {
                options.Password = new PasswordOptions
                {
                    RequireLowercase       = false,
                    RequireUppercase       = false,
                    RequireNonAlphanumeric = false,
                    RequireDigit           = false
                };
                options.User.RequireUniqueEmail      = false;
                options.SignIn.RequireConfirmedEmail = false;

                options.SignIn.RequireConfirmedPhoneNumber = true;
            });
            services.ConfigureApplicationCookie(options =>
            {
                options.LoginPath        = "/Account/Login";
                options.LogoutPath       = "/Account/LogOff";
                options.AccessDeniedPath = "/Account/AccessDenied";
            });

            services.AddAuthentication()
            .AddWeixinOpen(options =>
            {
                options.AppId      = Configuration["WeixinOpen:AppId"];
                options.AppSecret  = Configuration["WeixinOpen:AppSecret"];
                options.SaveTokens = true;
            })
            .AddWeixinAuth(options =>
            {
                options.AppId      = Configuration["WeixinAuth:AppId"];
                options.AppSecret  = Configuration["WeixinAuth:AppSecret"];
                options.SilentMode = false;     //不采用静默模式
                                                //options.SaveTokens = true;
            })
            .AddQQConnect(options =>
            {
                options.AppId  = Configuration["QQConnect:AppId"];
                options.AppKey = Configuration["QQConnect:AppKey"];
                //options.SaveTokens = true;

                QQConnectScopes.TryAdd(options.Scope,
                                       QQConnectScopes.get_user_info,
                                       QQConnectScopes.list_album,
                                       QQConnectScopes.upload_pic,
                                       QQConnectScopes.do_like);
            });

            services.AddTencentSms(options =>
            {
                options.SdkAppId = Configuration["TencentSms:SdkAppId"];
                options.AppKey   = Configuration["TencentSms:AppKey"];
            });

            services.AddViewDivert();

            services.AddMvc();
        }