コード例 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ECardDataContext ctx)
        {
            // global cors policy
            app.UseCors(x => x
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader());

            DbInitializer.Initialize(ctx);

            app.UseJwtServer(options =>
            {
                options.TokenEndpointPath         = "/api/Token";
                options.AccessTokenExpireTimeSpan = new TimeSpan(1, 0, 0);
                options.Issuer = "yourIssuerCode";
                //options.IssuerSigningKey = "fVGGS9A&3ULP$P-U5aFRGge!RmBRhRCENMY+A3Ckq2E2%HwVqC#^x7w*aU4B3P&ZE52A!uzCUtn+&E48nnY46YPt*^Ne5VwU%LG&w9qmxG$+9LrYPzz5_kDkF$FW2NCe5ud+xKh7Uka%DbcGukp=-pgXr!=wZ@rWvQSc^L%rn@3Qp^CT8Jz=wNF$f8=vA2zY2X9XSJd*3@AkpgSz=^##DFhtCnqn&5D^xVgZj$y5-&BbBPuzrga^UUndQ*^&nCPj";
                options.IssuerSigningKey            = _appSettings.Secret;
                options.AuthorizationServerProvider = new AuthorizationServerProvider
                {
                    OnGrantResourceOwnerCredentialsAsync = async(context) =>
                    {
                        var userService = context.Context.RequestServices.GetRequiredService <IUserService>();
                        var user        = userService.Authenticate(context.UserName, context.Password);
                        if (user == null)
                        {
                            context.SetError("The user name or password is incorrect.");
                            return;
                        }

                        var claims = new List <Claim>
                        {
                            new Claim(Constant.Claim.User.Id, user.Id.ToString()),
                            new Claim(Constant.Claim.User.UserName, user.Username),
                            new Claim(Constant.Claim.User.Name, $"{user.FirstName} {user.LastName}"),
                        };

                        context.Validated(claims);
                        await Task.FromResult(0);
                    }
                };
            });

            app.UseAuthentication();
            app.UseMvc();
        }
コード例 #2
0
 public ECardDetailService(ECardDataContext context)
 {
     _context = context;
 }
コード例 #3
0
 public GenericComponent(ECardDataContext context, IOptions <AppSettings> appSettings)
 {
     _context     = context;
     _appSettings = appSettings.Value;
 }
コード例 #4
0
 public UserService(ECardDataContext context)
 {
     _context = context;
 }
コード例 #5
0
 public XloRecordComponent(ECardDataContext context, IOptions <AppSettings> appSettings) : base(context, appSettings)
 {
     _context     = context;
     _appSettings = appSettings.Value;
 }
コード例 #6
0
 public RsvpService(ECardDataContext context, IOptions <AppSettings> appSettings)
 {
     _context     = context;
     _appSettings = appSettings.Value;
 }
コード例 #7
0
ファイル: Program.cs プロジェクト: skyclasher/e-kad-webapi
        static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json");
            var configuration = builder.Build();

            var optionsBuilder = new DbContextOptionsBuilder <ECardDataContext>();

            optionsBuilder.UseMySql(configuration["conn"]);

            ECardDataContext eCardDataContext = new ECardDataContext(optionsBuilder.Options);
            IUserService     userService      = new UserService(eCardDataContext);

            Console.Write("Enter First Name: ");
            string firstName = Console.ReadLine();

            Console.Write("Enter Last Name: ");
            string lastName = Console.ReadLine();

            Console.Write("Enter username: "******"Enter password: "******"";

            do
            {
                ConsoleKeyInfo key = Console.ReadKey(true);
                // Backspace Should Not Work
                if (key.Key != ConsoleKey.Backspace && key.Key != ConsoleKey.Enter)
                {
                    pass += key.KeyChar;
                    Console.Write("*");
                }
                else
                {
                    if (key.Key == ConsoleKey.Backspace && pass.Length > 0)
                    {
                        pass = pass.Substring(0, (pass.Length - 1));
                        Console.Write("\b \b");
                    }
                    else if (key.Key == ConsoleKey.Enter)
                    {
                        break;
                    }
                }
            } while (true);

            User user = new User()
            {
                FirstName = firstName,
                LastName  = lastName,
                Username  = username,
            };

            userService.Create(user, pass);

            Console.WriteLine("User creation completed.");
        }