Esempio n. 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
                              BettingGameContext dbContext)
        {
            app.UseDeveloperExceptionPage();
            app.UseDatabaseErrorPage();

            BettingGameDataInitializer.Seed(dbContext);

            app.UseCors(builder => builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin());

            var settings = app.ApplicationServices.GetService <IOptions <Auth0Settings> >();

            var options = new JwtBearerOptions
            {
                Audience  = settings.Value.ClientId,
                Authority = $"https://{settings.Value.Domain}",
                TokenValidationParameters = new TokenValidationParameters
                {
                    NameClaimType = "name",
                    RoleClaimType = "https://schemas.testa.eu.auth0.com/roles"
                },
                Events =
                    new JwtBearerEvents
                {
                    OnAuthenticationFailed =
                        context => Task.FromResult(0),
                    OnTokenValidated = context =>
                    {
                        var claimsIdentity = context.Ticket.Principal.Identity as ClaimsIdentity;
                        claimsIdentity?.AddClaim(new Claim("id_token",
                                                           context.Request.Headers["Authorization"][0].Substring(context.Ticket.AuthenticationScheme.Length + 1)));

                        // OPTIONAL: you can read/modify the claims that are populated based on the JWT
                        //claimsIdentity.AddClaim(new Claim(ClaimTypes.Name, claimsIdentity.FindFirst("name").Value));
                        //claimsIdentity.AddClaim(new Claim(ClaimTypes.Role, claimsIdentity.FindFirst("role").Value));
                        return(Task.FromResult(0));
                    }
                }
            };

            app.UseJwtBearerAuthentication(options);

            app.UseMvc();
        }
Esempio n. 2
0
 public UnitOfWork(BettingGameContext context)
 {
     _context = context;
 }
Esempio n. 3
0
 public TipsRepository(BettingGameContext context)
 {
     _context = context;
 }
Esempio n. 4
0
 public MatchesRepository(BettingGameContext bettingGameContext)
 {
     _context = bettingGameContext;
 }