Esempio n. 1
0
        public static void Configure(IAppBuilder app, IAuthApplicationService authAppService)
        {
            var OAuthOptions = new OAuthAuthorizationServerOptions
            {
                TokenEndpointPath         = new PathString("/security/token"),
                Provider                  = new AuthorizationProvider(authAppService),
                AccessTokenExpireTimeSpan = TimeSpan.FromHours(2),
                AllowInsecureHttp         = true,
                RefreshTokenProvider      = new RefreshTokenProvider()
            };

            var bearerOptions = new OAuthBearerAuthenticationOptions()
            {
                AccessTokenFormat   = OAuthOptions.AccessTokenFormat,
                AccessTokenProvider = OAuthOptions.AccessTokenProvider,
                AuthenticationMode  = OAuthOptions.AuthenticationMode,
                AuthenticationType  = OAuthOptions.AuthenticationType,
                Description         = OAuthOptions.Description,
                Provider            = new BearerAuthenticationProvider(),
                SystemClock         = OAuthOptions.SystemClock
            };

            app.UseOAuthAuthorizationServer(OAuthOptions);

            OAuthBearerAuthenticationExtensions.UseOAuthBearerAuthentication(app, bearerOptions);
        }
Esempio n. 2
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        //public void ConfigureAuth(IAppBuilder app)
        //{
        //    // Enable the application to use a cookie to store information for the signed in user
        //    // and to use a cookie to temporarily store information about a user logging in with a third party login provider
        //    app.UseCookieAuthentication(new CookieAuthenticationOptions());
        //    app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

        //    // Enable the application to use bearer tokens to authenticate users
        //    app.UseOAuthBearerTokens(OAuthOptions);

        //    // Enable CORS
        //    app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

        //    // Uncomment the following lines to enable logging in with third party login providers
        //    //app.UseMicrosoftAccountAuthentication(
        //    //    clientId: "",
        //    //    clientSecret: "");

        //    //app.UseTwitterAuthentication(
        //    //    consumerKey: "",
        //    //    consumerSecret: "");

        //    //app.UseFacebookAuthentication(
        //    //    appId: "",
        //    //    appSecret: "");

        //    //app.UseGoogleAuthentication();
        //}
        public void ConfigureOAuth(IAppBuilder app)
        {
            OAuthAuthorizationServerOptions OAuthOptions = new OAuthAuthorizationServerOptions()
            {
                AllowInsecureHttp         = true,
                TokenEndpointPath         = new PathString("/token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
                Provider = new AuthorizationServerProvider()
            };

            OAuthBearerAuthenticationOptions OAuthBearerOptions = new OAuthBearerAuthenticationOptions();

            OAuthBearerOptions.AccessTokenFormat   = OAuthOptions.AccessTokenFormat;
            OAuthBearerOptions.AccessTokenProvider = OAuthOptions.AccessTokenProvider;
            OAuthBearerOptions.AuthenticationMode  = OAuthOptions.AuthenticationMode;
            OAuthBearerOptions.AuthenticationType  = OAuthOptions.AuthenticationType;
            OAuthBearerOptions.Description         = OAuthOptions.Description;
            // The provider is the only object we need to redefine. See below for the implementation
            OAuthBearerOptions.Provider    = new Authorizefilter();
            OAuthBearerOptions.SystemClock = OAuthOptions.SystemClock;

            // Token Generation
            OAuthBearerAuthenticationExtensions.UseOAuthBearerAuthentication(app, OAuthBearerOptions);
            //app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions()
            //{
            //   // AuthenticationMode =Microsoft.Owin.Security.AuthenticationMode.Active,

            //    Provider = new Authorizefilter(),
            //});
            app.UseOAuthAuthorizationServer(OAuthOptions);
        }
Esempio n. 3
0
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath          = new PathString("/Account/Login"),
                Provider           = new CookieAuthenticationProvider()
                {
                    OnApplyRedirect = ctx =>
                    {
                        if (!ctx.Request.Path.StartsWithSegments(new PathString("/api")))     //Prevent login redirect when using api
                        {
                            ctx.Response.Redirect(ctx.RedirectUri);
                        }
                    }
                }
            });
            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
            OAuthBearerAuthenticationExtensions.UseOAuthBearerAuthentication(app, OAuthBearerOptions);


            app.UseTwitterAuthentication(
                consumerKey: "REDACTED",
                consumerSecret: "REDACTED");

            app.UseFacebookAuthentication(
                appId: "REDACTED",
                appSecret: "REDACTED");
        }
Esempio n. 4
0
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context and user manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);

            // Enable the application to use a cookie to store information for the signed in user
            // and to use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseCookieAuthentication(new CookieAuthenticationOptions());
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Configure the application for OAuth based flow
            PublicClientId = "self";
            OAuthOptions   = new OAuthAuthorizationServerOptions
            {
                TokenEndpointPath         = new PathString("/Token"),
                Provider                  = new ApplicationOAuthProvider(PublicClientId),
                AuthorizeEndpointPath     = new PathString("/api/Account/ExternalLogin"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
                AllowInsecureHttp         = true
            };

            OAuthBearerOptions = new OAuthBearerAuthenticationOptions();
            OAuthBearerOptions.AccessTokenFormat   = OAuthOptions.AccessTokenFormat;
            OAuthBearerOptions.AccessTokenProvider = OAuthOptions.AccessTokenProvider;
            OAuthBearerOptions.AuthenticationMode  = OAuthOptions.AuthenticationMode;
            OAuthBearerOptions.AuthenticationType  = OAuthOptions.AuthenticationType;
            OAuthBearerOptions.Description         = OAuthOptions.Description;
            OAuthBearerOptions.Provider            = new CustomBearerAuthenticationProvider();
            OAuthBearerOptions.SystemClock         = OAuthOptions.SystemClock;

            // Enable the application to use bearer tokens to authenticate users
            app.UseOAuthBearerTokens(OAuthOptions);
            OAuthBearerAuthenticationExtensions.UseOAuthBearerAuthentication(app, OAuthBearerOptions);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //    consumerKey: "",
            //    consumerSecret: "");

            app.UseFacebookAuthentication(
                appId: ConfigurationManager.AppSettings["facebookAppId"],
                appSecret: ConfigurationManager.AppSettings["facebookAppSecret"]);

            /*app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions
             * {
             *  ClientId = "79011049554-0ck6n5t46ckpr168ip6biv0dmicbphpj.apps.googleusercontent.com",
             *  ClientSecret = "4Du6V1xAX9IuU28iKSg3I4dM"
             * });*/
        }