Ejemplo n.º 1
0
        public void Configuration(IAppBuilder app)
        {
            // Register  UserManager for OWIN
            app.CreatePerOwinContext <IdentityUserManager>(IdentityUserManager.Create);

            // Use cookies for authentication and authorization
            // LoginPath - path to redirect unauthenticated user
            app.UseCookieAuthentication(new Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath          = new PathString("/Account/Login")
            });

            // Receive settings about google application
            GoogleSection section = (GoogleSection)WebConfigurationManager.GetSection("googleSection");
            GoogleElement elem    = section.GoogleElement;

            AdminSection     adminSection     = (AdminSection)WebConfigurationManager.GetSection("adminSection");
            AdminsCollection adminsCollection = adminSection.AdminEmails;

            for (int i = 0; i < adminsCollection.Count; i++)
            {
                var uuu = adminsCollection[i];
            }

            // Use external cookies
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
            // Google authentication
            app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = elem.ClientId,
                ClientSecret = elem.ClientSecret,
                CallbackPath = new PathString("/Account/LoginCallback/")
            });
        }
Ejemplo n.º 2
0
        public static GoogleSection Google(this CustomConfiguration config)
        {
            lock (_lockObjectGoogle)
            {
                if (_googleSection == null)
                {
                    _googleSection = ConfigurationManager.GetSection(GoogleSection.SectionName) as GoogleSection;

                    if (_googleSection == null)
                    {
                        throw new ConfigurationErrorsException(String.Format(ConfigurationMessages.SectionNotFound, GoogleSection.SectionName));
                    }
                }
            }

            return(_googleSection);
        }