Пример #1
0
        public async Task GetCodeAsync(string code, string state)
        {
            var token = await EVESwagger.GetToken("authorization_code", code);

            var auth_char = await EVESwagger.Verify(token);


            using (var context = new StructureContext())
            {
                //if we have on update it to use the token we just got or bail.
                var fromdb = context.Characters.Where(c => c.CharacterID == auth_char.CharacterID).FirstOrDefault();
                if (fromdb == null)
                {
                    context.Characters.Attach(auth_char);
                    //If we have just signed in for the first time, force update the notifications for that character
                    var ignoreWarning = StructureWatch.Services.Polling.UpdateOneCharacter(context, auth_char, true);
                }
                else
                {
                    fromdb.ConsumeToken(token);
                    context.Characters.Update(fromdb);
                }

                context.SaveChanges();


                //sign in the user:
                var principal = new EveSSOClaim().BuildClaimsPrincipal(context, auth_char.CharacterName);
                await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);

                HttpContext.User = principal;
            }

            Response.Redirect("/LoggedIn");
        }
Пример #2
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)
        {
            //SETUP

            EVESwagger.InitClient(new SwaggerConfig(Configuration.GetSection("EsiConfig")));

            services.Configure <CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded    = context => false;
                options.MinimumSameSitePolicy = SameSiteMode.Strict;
                options.HttpOnly = HttpOnlyPolicy.Always;
            });

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(
                options =>
            {
                options.LoginPath        = new PathString("/api/SSO/Login");
                options.LogoutPath       = new PathString("/api/SSO/logout");
                options.AccessDeniedPath = new PathString("/Unauthorized");
                options.Cookie.Name      = "StructureWatch_Auth";
            }
                );

            services.AddControllers();
            services.AddRazorPages()
            .AddRazorRuntimeCompilation();

            services.AddDbContext <StructureContext>(options => options.UseSqlite());
        }
Пример #3
0
 public void GetSSOSignInURL()
 {
     Response.Redirect(EVESwagger.GetAuthUrl(new List <string> {
         "esi-characters.read_notifications.v1"
     },
                                             "Login"));
 }