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="SalesforceAuthenticationMiddleware"/> middleware to the specified /// <see cref="IApplicationBuilder"/>, which enables Salesforce authentication capabilities. /// </summary> /// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param> /// <param name="options">A <see cref="SalesforceAuthenticationOptions"/> that specifies options for the middleware.</param> /// <returns>A reference to this instance after the operation has completed.</returns> public static IApplicationBuilder UseSalesforceAuthentication( [NotNull] this IApplicationBuilder app, [NotNull] SalesforceAuthenticationOptions options) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } return(app.UseMiddleware <SalesforceAuthenticationMiddleware>(Options.Create(options))); }
/// <summary> /// Adds the <see cref="SalesforceAuthenticationMiddleware"/> middleware to the specified /// <see cref="IApplicationBuilder"/>, which enables Salesforce 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="SalesforceAuthenticationOptions"/>.</param> /// <returns>A reference to this instance after the operation has completed.</returns> public static IApplicationBuilder UseSalesforceAuthentication( [NotNull] this IApplicationBuilder app, [NotNull] Action <SalesforceAuthenticationOptions> configuration) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } var options = new SalesforceAuthenticationOptions(); configuration(options); return(app.UseMiddleware <SalesforceAuthenticationMiddleware>(Options.Create(options))); }
// 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); var instanceName = ConfigurationManager.AppSettings["InstanceName"]; var salesforceEndpoints = new SalesforceAuthenticationOptions.SalesforceAuthenticationEndpoints { AuthorizationEndpoint = string.Format(@"https://{0}.salesforce.com/services/oauth2/authorize", instanceName), TokenEndpoint = string.Format(@"https://{0}.salesforce.com/services/oauth2/token", instanceName) }; var options = new SalesforceAuthenticationOptions { ClientId = ConfigurationManager.AppSettings["ConsumerKey"], ClientSecret = ConfigurationManager.AppSettings["ConsumerSecret"], Endpoints = salesforceEndpoints, Provider = new SalesforceAuthenticationProvider() { OnAuthenticated = async context => { // When the user authenticates with Salesforce, get the values that we will need later to interact with their instance. context.Identity.AddClaim(new Claim(SalesforceClaims.AccessToken, context.AccessToken)); context.Identity.AddClaim(new Claim(SalesforceClaims.RefreshToken, context.RefreshToken)); context.Identity.AddClaim(new Claim(SalesforceClaims.InstanceUrl, context.InstanceUrl)); await Task.FromResult(0); } } }; app.UseSalesforceAuthentication(options); }
// 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); var options = new SalesforceAuthenticationOptions { ClientId = "3MVG9uudbyLbNPZODiKsxXr8SMyGbRmYPaVTqBepnJwZj9tFyVCUe.5I2r5P9oZJDqXdrXOA0fT1ZPit5avRj", ClientSecret = "cadbc018229e40d581ef98917f07c25a", Endpoints = new SalesforceAuthenticationOptions.SalesforceAuthenticationEndpoints { AuthorizationEndpoint = "https://sales-buddy-dev-ed.my.salesforce.com/services/oauth2/authorize", TokenEndpoint = "https://sales-buddy-dev-ed.my.salesforce.com/services/oauth2/token" } }; app.UseSalesforceAuthentication(options); // 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(new GoogleOAuth2AuthenticationOptions() //{ // ClientId = "", // ClientSecret = "" //}); }