示例#1
0
        public static IApplicationBuilder UseInstagramAuthentication(
            [NotNull] this IApplicationBuilder app,
            [NotNull] Action <InstagramAuthenticationOptions> configuration)
        {
            var options = new InstagramAuthenticationOptions();

            configuration(options);

            return(app.UseMiddleware <InstagramAuthenticationMiddleware>(options));
        }
示例#2
0
        /// <summary>
        /// Authenticate users using Facebook
        /// </summary>
        /// <param name="app">The <see cref="IAppBuilder"/> passed to the configuration method</param>
        /// <param name="options">Middleware configuration options</param>
        /// <returns>The updated <see cref="IAppBuilder"/></returns>
        public static IAppBuilder UseInstagramAuthentication(this IAppBuilder app, InstagramAuthenticationOptions options)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            app.Use(typeof(InstagramAuthenticationMiddleware), app, options);
            return(app);
        }
        public TenantMiddleware(
            RequestDelegate next,
            TenantService tenantService,
            IAuthenticationSchemeProvider oauthProvider,
            IMemoryCache memoryCache,
            IdentityServerOptions identityServerOptions,

            IOptionsMonitor <AmazonAuthenticationOptions> amazonOptions,
            IOptionsMonitor <FacebookOptions> facebookOptions,
            IOptionsMonitor <GitHubOptions> githubOptions,
            IOptionsMonitor <GitterAuthenticationOptions> gitterOptions,
            IOptionsMonitor <GoogleOptions> googleOptions,
            IOptionsMonitor <InstagramAuthenticationOptions> instagramOptions,
            IOptionsMonitor <LinkedInAuthenticationOptions> linkedinOptions,
            IOptionsMonitor <MicrosoftAccountOptions> microsoftOptions,
            IOptionsMonitor <PaypalAuthenticationOptions> paypalOptions,
            IOptionsMonitor <QQOptions> qqOptions,
            IOptionsMonitor <RedditAuthenticationOptions> redditOptions,
            IOptionsMonitor <SalesforceAuthenticationOptions> salesforceOptions,
            IOptionsMonitor <TwitterOptions> twitterOptions,
            IOptionsMonitor <VisualStudioAuthenticationOptions> visualstudioOptions,
            IOptionsMonitor <WeiboOptions> weiboOptions,
            IOptionsMonitor <WeixinOptions> weixinOptions,
            IOptionsMonitor <WordPressAuthenticationOptions> wordpressOptions
            )
        {
            _next                  = next;
            _tenantService         = tenantService;
            _oauthProvider         = oauthProvider;
            _memoryCache           = memoryCache;
            _identityServerOptions = identityServerOptions;

            _amazonOptions       = amazonOptions.CurrentValue;
            _facebookOptions     = facebookOptions.CurrentValue;
            _githubOptions       = githubOptions.CurrentValue;
            _gitterOptions       = gitterOptions.CurrentValue;
            _googleOptions       = googleOptions.CurrentValue;
            _instagramOptions    = instagramOptions.CurrentValue;
            _linkedinOptions     = linkedinOptions.CurrentValue;
            _microsoftOptions    = microsoftOptions.CurrentValue;
            _paypalOptions       = paypalOptions.CurrentValue;
            _qqOptions           = qqOptions.CurrentValue;
            _redditOptions       = redditOptions.CurrentValue;
            _salesforceOptions   = salesforceOptions.CurrentValue;
            _twitterOptions      = twitterOptions.CurrentValue;
            _visualstudioOptions = visualstudioOptions.CurrentValue;
            _weiboOptions        = weiboOptions.CurrentValue;
            _weixinOptions       = weixinOptions.CurrentValue;
            _wordpressOptions    = wordpressOptions.CurrentValue;
        }
        /// <summary>
        /// Adds the <see cref="InstagramAuthenticationMiddleware"/> middleware to the specified
        /// <see cref="IApplicationBuilder"/>, which enables Instagram authentication capabilities.
        /// </summary>
        /// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
        /// <param name="options">A <see cref="InstagramAuthenticationOptions"/> that specifies options for the middleware.</param>
        /// <returns>A reference to this instance after the operation has completed.</returns>
        public static IApplicationBuilder UseInstagramAuthentication(
            [NotNull] this IApplicationBuilder app,
            [NotNull] InstagramAuthenticationOptions options)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(app.UseMiddleware <InstagramAuthenticationMiddleware>(Options.Create(options)));
        }
        /// <summary>
        /// Adds the <see cref="InstagramAuthenticationMiddleware"/> middleware to the specified
        /// <see cref="IApplicationBuilder"/>, which enables Instagram authentication capabilities.
        /// </summary>
        /// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
        /// <param name="configuration">An action delegate to configure the provided <see cref="InstagramAuthenticationOptions"/>.</param>
        /// <returns>A reference to this instance after the operation has completed.</returns>
        public static IApplicationBuilder UseInstagramAuthentication(
            [NotNull] this IApplicationBuilder app,
            [NotNull] Action <InstagramAuthenticationOptions> configuration)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var options = new InstagramAuthenticationOptions();

            configuration(options);

            return(app.UseMiddleware <InstagramAuthenticationMiddleware>(Options.Create(options)));
        }
示例#6
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, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.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
            // Configure the sign in cookie
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath          = new PathString("/Account/Login"),
                Provider           = new CookieAuthenticationProvider
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Get the config used by InstaSharp
            InstagramConfig config = Dependencies.InstagramConfig;

            // Wire up Instagram authentication so that we can access the media published by a user.
            var options = new InstagramAuthenticationOptions()
            {
                ClientId     = config.ClientId,
                ClientSecret = config.ClientSecret,
                Provider     = new InstagramAuthenticationProvider
                {
                    OnAuthenticated = context =>
                    {
                        // Retrieve the OAuth access token to store for subsequent API calls
                        OAuthResponse response = new OAuthResponse
                        {
                            User = new UserInfo
                            {
                                Id             = long.Parse(context.Id),
                                FullName       = context.Name,
                                ProfilePicture = context.ProfilePicture,
                                Username       = context.UserName,
                            },
                            AccessToken = context.AccessToken,
                        };

                        string userId      = context.Id;
                        string accessToken = context.AccessToken;

                        // Store the token in memory so that we can use it for accessing media. In a real scenario
                        // this would be stored somewhere else.
                        Dependencies.Tokens[userId] = response;
                        return(Task.FromResult(true));
                    }
                }
            };

            app.UseInstagramInAuthentication(options);
        }
示例#7
0
 public static IApplicationBuilder UseInstagramAuthentication(
     [NotNull] this IApplicationBuilder app,
     [NotNull] InstagramAuthenticationOptions options)
 {
     return(app.UseMiddleware <InstagramAuthenticationMiddleware>(options));
 }
        // For more information on configuring authentication, please visit https://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.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
            // Configure the sign in cookie
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath          = new PathString("/Account/Login"),
                Provider           = new CookieAuthenticationProvider
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

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

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");
            FacebookAuthenticationOptions facebookAuthenticationOptions = new FacebookAuthenticationOptions()
            {
                AppId     = ConfigurationManager.AppSettings["FacebookAppId"],
                AppSecret = ConfigurationManager.AppSettings["FacebookAppSecret"],
                Provider  = new FacebookAuthenticationProvider()
                {
                    OnAuthenticated = (ctx) =>
                    {
                        ctx.Identity.AddClaim(new Claim("fb_access_token", ctx.AccessToken, ClaimValueTypes.String, "Facebook"));
                        return(Task.FromResult(0));
                    }
                }
            };

            facebookAuthenticationOptions.Scope.Add("pages_show_list");

            InstagramAuthenticationOptions instagramAuthenticationOptions = new
                                                                            InstagramAuthenticationOptions()
            {
                ClientId     = ConfigurationManager.AppSettings["InstagramClientId"],
                ClientSecret = ConfigurationManager.AppSettings["InstagramClientSecret"]
            };

            app.UseFacebookAuthentication(facebookAuthenticationOptions);
            app.UseInstagramInAuthentication(instagramAuthenticationOptions);
            //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            //{
            //    ClientId = "",
            //    ClientSecret = ""
            //});
        }
示例#9
0
        public void ConfigureInstagram(IAppBuilder app)
        {
            /* -------------------------------------------------------------------------------
             * Normal configuration
             * ------------------------------------------------------------------------------- */

            //app.UseInstagramInAuthentication("Your client id", "Your client secret");

            /* -------------------------------------------------------------------------------
             * Request extra permissions
             * ------------------------------------------------------------------------------- */

            //var options = new InstagramAuthenticationOptions()
            //{
            //    ClientId = "Your client id",
            //    ClientSecret = "Your client secret"
            //};
            //options.Scope.Add("likes");
            //app.UseInstagramInAuthentication(options);

            /* -------------------------------------------------------------------------------
             * Specify an alternate callback path. In this case you need to make sure that
             * the redirect URI you specify when registering the application in Instagram
             * matches this exactly
             * ------------------------------------------------------------------------------- */

            //var options = new InstagramAuthenticationOptions()
            //{
            //    ClientId = "Your client id",
            //    ClientSecret = "Your client secret",
            //    CallbackPath = new PathString("/oauth-redirect/instagram")
            //};
            //app.UseInstagramInAuthentication(options);

            /* -------------------------------------------------------------------------------
             * Retrieve the access token and other user information
             * ------------------------------------------------------------------------------- */

            var options = new InstagramAuthenticationOptions()
            {
                ClientId     = ConfigurationManager.AppSettings["INSTAGRAM_CLIENT_ID"],
                ClientSecret = ConfigurationManager.AppSettings["INSTAGRAM_CLIENT_SECRET"],
                CallbackPath = new PathString("/en/signin-instagram"),
                //CallbackPath = new PathString("/en/Account/ExternalLoginCallback"),
            };

            options.Provider = new InstagramAuthenticationProvider
            {
                OnAuthenticated = context =>
                {
                    try
                    {
                        // Retrieve the OAuth access token to store for subsequent API calls
                        //string accessToken = context.AccessToken;

                        // Retrieve the username
                        //string userName = context.UserName;

                        // Retrieve the user's full name
                        //string fullName = context.Name;

                        // You can even retrieve the full JSON-serialized user
                        //var serializedUser = context.User;
                        context.Identity.AddClaim(new Claim(_ClaimTypes.ExternalProviderAccessToken, context.AccessToken));
                        context.Identity.AddClaim(new Claim(ClaimTypes.UserData, context.User.ToString()));
                    }
                    catch (Exception e)
                    {
                        File.AppendAllText(HttpContext.Current.Server.MapPath("~/Logs.txt"), DateTime.UtcNow.ToShortDateString() + " - " + HttpContext.Current.Request.Browser.Type + "\n\n" + e.Message + "\n\n===============================\n\n");
                    }
                    return(Task.FromResult(true));
                }
            };
            app.UseInstagramInAuthentication(options);
        }