public void ConfigureOAuth(IAppBuilder app) { //use a cookie to temporarily store information about a user logging in with a third party login provider app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie); OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions() { AllowInsecureHttp = true, TokenEndpointPath = new PathString("/token"), AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30), Provider = new SimpleAuthorizationServerProvider(), RefreshTokenProvider = new SimpleRefreshTokenProvider() }; // Token Generation app.UseOAuthAuthorizationServer(OAuthServerOptions); app.UseOAuthBearerAuthentication(OAuthBearerOptions); //Configure Google External Login googleAuthOptions = new GoogleOAuth2AuthenticationOptions() { ClientId = "719973586746-vmm531jii6i8jjvr4m2ie006ge7nvhp9.apps.googleusercontent.com", ClientSecret = "bvJbPL2uEgfldC-IvUE8elLU", Provider = new GoogleAuthProvider() }; app.UseGoogleAuthentication(googleAuthOptions); //Configure Facebook External Login facebookAuthOptions = new FacebookAuthenticationOptions() { AppId = "2005404516451956", AppSecret = "3588590b0f8cad26418cf5d8075af194", Provider = new FacebookAuthProvider() }; app.UseFacebookAuthentication(facebookAuthOptions); }
public void ConfigureOAuth(IAppBuilder app) { //use a cookie to temporarily store information about a user logging in with a third party login provider app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie); OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions() { AllowInsecureHttp = true, TokenEndpointPath = new PathString("/token"), AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30), Provider = new SimpleAuthorizationServerProvider(), RefreshTokenProvider = new SimpleRefreshTokenProvider() }; // Token Generation app.UseOAuthAuthorizationServer(OAuthServerOptions); app.UseOAuthBearerAuthentication(OAuthBearerOptions); //Configure Google External Login googleAuthOptions = new GoogleOAuth2AuthenticationOptions() { ClientId = "477213065765-bect2aabnrd5fi3uqub1qosbq4096564.apps.googleusercontent.com", ClientSecret = "z7dCqSvOhuVBO6zHb5fFl28w", Provider = new GoogleAuthProvider() }; app.UseGoogleAuthentication(googleAuthOptions); //Configure Facebook External Login facebookAuthOptions = new FacebookAuthenticationOptions() { AppId = "235302619851727", AppSecret = "489a1436f93c35dd8cd4ca5d4997473e", Provider = new FacebookAuthProvider() }; app.UseFacebookAuthentication(facebookAuthOptions); }
public void ConfigureOAuth(IAppBuilder app, Container container) { Func <IAuthRepository> authRepositoryFactory = container.GetInstance <IAuthRepository>; //Use a cookie to temporarily store information about a user logging in with a third party login provider app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie); OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); var oAuthServerOptions = new OAuthAuthorizationServerOptions() { AllowInsecureHttp = true, TokenEndpointPath = new PathString("/token"), AccessTokenExpireTimeSpan = TimeSpan.FromDays(1), Provider = new BlogAggregatorAuthorizationServerProvider(authRepositoryFactory), }; // Token Generation app.UseOAuthAuthorizationServer(oAuthServerOptions); app.UseOAuthBearerAuthentication(OAuthBearerOptions); // Set third-party login provider options GoogleAuthOptions = new GoogleOAuth2AuthenticationOptions { ClientId = "77265186922-n2f9s9pfs6qi90pm9arl6vo1r0hjeatd.apps.googleusercontent.com", ClientSecret = "Xp6BVnYNweq9ceha-vnddFs-", Provider = new GoogleAuthProvider() }; app.UseGoogleAuthentication(GoogleAuthOptions); //FacebookAuthOptions = new FacebookAuthenticationOptions() //{ // AppId = "xxx", // AppSecret = "xxx", // Provider = new FacebookAuthProvider() //}; //app.UseFacebookAuthentication(FacebookAuthOptions); }
public void ConfigureOAuth(IAppBuilder app) { //use a cookie to temporarily store information about a user logging in with a third party login provider app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie); OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions() { AllowInsecureHttp = true, TokenEndpointPath = new PathString("/token"), AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30), Provider = new SimpleAuthorizationServerProvider(), RefreshTokenProvider = new SimpleRefreshTokenProvider() }; // Token Generation app.UseOAuthAuthorizationServer(OAuthServerOptions); app.UseOAuthBearerAuthentication(OAuthBearerOptions); //Configure Google External Login googleAuthOptions = new GoogleOAuth2AuthenticationOptions() { ClientId = "xxxxxx", ClientSecret = "xxxxxx", Provider = new GoogleAuthProvider() }; app.UseGoogleAuthentication(googleAuthOptions); //Configure Facebook External Login facebookAuthOptions = new FacebookAuthenticationOptions() { AppId = "xxxxxx", AppSecret = "xxxxxx", Provider = new FacebookAuthProvider() }; app.UseFacebookAuthentication(facebookAuthOptions); }
public void ConfigureAuth(IAppBuilder app) { System.Data.Entity.Database.SetInitializer <CRMDb>(null); System.Data.Entity.Database.SetInitializer <EfUnitOfWork>(null); ApplicationUserManager.UserStore = IoC.Container.GetInstance <IUserStore <SmartTouch.CRM.Identity.IdentityUser> >(); ApplicationUserManager.ThirdPartyAuthenticationRepository = IoC.Container.GetInstance <IThirdPartyAuthenticationRepository>(); app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Login/Login"), ExpireTimeSpan = new TimeSpan(1, 0, 0), SlidingExpiration = true }); app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions { AllowInsecureHttp = true, TokenEndpointPath = new PathString("/token"), AccessTokenExpireTimeSpan = TimeSpan.FromHours(8), Provider = new SmartTouchAuthorizationServerProvider(), }); OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); app.UseOAuthBearerAuthentication(OAuthBearerOptions); var hubsConfiguration = new HubConfiguration(); hubsConfiguration.EnableDetailedErrors = true; var idProvider = new CustomUserIdProvider(); GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider), () => idProvider); app.MapSignalR(hubsConfiguration); //app.Map("https://s.smarttouch.net/signalr", map => // { // map.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll); // map.RunSignalR(hubsConfiguration); // }); }
public void ConfigureOAuth(IAppBuilder app) { app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); OAuthAuthorizationServerOptions oAuthServerOptions = new OAuthAuthorizationServerOptions() { AllowInsecureHttp = true, TokenEndpointPath = new PathString("/token"), AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30), Provider = new SimpleAuthorizationServerProvider(), RefreshTokenProvider = new SimpleRefreshTokenProvider() }; // Token Generation app.UseOAuthAuthorizationServer(oAuthServerOptions); app.UseOAuthBearerAuthentication(OAuthBearerOptions); //Configure Google External Login googleAuthOptions = new GoogleOAuth2AuthenticationOptions() { ClientId = "xxx", ClientSecret = "xxx", Provider = new GoogleAuthProvider() }; app.UseGoogleAuthentication(googleAuthOptions); //Configure Facebook External Login facebookAuthOptions = new FacebookAuthenticationOptions() { AppId = "xxx", AppSecret = "xxx", Provider = new FacebookAuthProvider() }; app.UseFacebookAuthentication(facebookAuthOptions); }
private void ConfigureOAuthTokenGeneration(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); app.CreatePerOwinContext <ApplicationRoleManager>(ApplicationRoleManager.Create); //use a cookie to temporarily store information about a user logging in with a third party login provider app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie); OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); // Plugin the OAuth bearer JSON Web Token tokens generation and Consumption will be here OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions() { //For Dev enviroment only (on production should be AllowInsecureHttp = false) AllowInsecureHttp = true, TokenEndpointPath = new PathString("/oauth/token"), AccessTokenExpireTimeSpan = TimeSpan.FromHours(1), Provider = new CustomOAuthProvider(), AccessTokenFormat = new CustomJwtFormat("https://localhost:44350"), RefreshTokenProvider = new SimpleRefreshTokenProvider() }; // OAuth 2.0 Bearer Access Token Generation app.UseOAuthAuthorizationServer(OAuthServerOptions); app.UseOAuthBearerAuthentication(OAuthBearerOptions); //Configure Facebook External Login //PublicClientId = "self"; facebookAuthOptions = new FacebookAuthenticationOptions() { AppId = "3058390497587092", AppSecret = "56486ff5e9af123b45a8fadce341eb91", Provider = new FacebookAuthProvider() }; app.UseFacebookAuthentication(facebookAuthOptions); }
public void ConfigureOAuth(IAppBuilder app) { //use a cookie to temporarily store information about a user logging in with a third party login provider app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie); OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions() { AllowInsecureHttp = true, TokenEndpointPath = new PathString("/token"), AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30), Provider = new SimpleAuthorizationServerProvider(), RefreshTokenProvider = new SimpleRefreshTokenProvider() }; // Token Generation app.UseOAuthAuthorizationServer(OAuthServerOptions); app.UseOAuthBearerAuthentication(OAuthBearerOptions); //Configure Google External Login googleAuthOptions = new GoogleOAuth2AuthenticationOptions() { ClientId = "849317458859-re4g26oelji921129c33jnrff95gds4v.apps.googleusercontent.com", ClientSecret = "Ih5M-f6_Yph7MHFsdUob8LB_", Provider = new GoogleAuthProvider() }; app.UseGoogleAuthentication(googleAuthOptions); //Configure Facebook External Login facebookAuthOptions = new FacebookAuthenticationOptions() { AppId = "1598106220467246", AppSecret = "9f4e40ee76db72ab731d3e348b654f65", Provider = new FacebookAuthProvider() }; app.UseFacebookAuthentication(facebookAuthOptions); }
private 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); app.CreatePerOwinContext <ApplicationRoleManager>(ApplicationRoleManager.Create); OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); OAuthServerOptions = new OAuthAuthorizationServerOptions() { //IMPORTANT: Dev only (AllowInsecureHttp), should set to 'false' on production AllowInsecureHttp = true, TokenEndpointPath = new PathString("/oauth/token"), AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(60), Provider = new AuthorizationServerProvider() }; // Token Generation app.UseOAuthAuthorizationServer(OAuthServerOptions); // Token Consumption app.UseOAuthBearerAuthentication(OAuthBearerOptions); }
public void Configuration(IAppBuilder app) { //use a cookie to temporarily store information about a user logging in with a third party login provider app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie); OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); app.UseOAuthBearerAuthentication(OAuthBearerOptions); //Configure Facebook External Login facebookAuthOptions = new FacebookAuthenticationOptions() { AppId = "1392336224214575", AppSecret = "8bc0388b3b1985a8921166cfd5151ede", Provider = new FacebookAuthProvider() }; facebookAuthOptions.Scope.Add("user_friends"); app.UseFacebookAuthentication(facebookAuthOptions); // HttpConfiguration config = new HttpConfiguration(); // config.Filters.Add(new AuthorizeAttribute()); // app.UseWebApi(config); }
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 public void ConfigureAuth(IAppBuilder app) { // app.CreatePerOwinContext<UserManager>(() => new UserManager(new UserStore())); // app.CreatePerOwinContext<Custom.Identity.RoleManager>(() => new Custom.Identity.RoleManager(new Custom.Identity.RoleStore())); //app.CreatePerOwinContext<SignInService>((options, context) => new SignInService(context.GetUserManager<UserManager>(), context.Authentication)); app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie); OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); var OAuthOptions = new OAuthAuthorizationServerOptions { TokenEndpointPath = new PathString("/Token"), Provider = new Api.Socioboard.App_Start.ApplicationOAuthServerProvider("self"), AccessTokenExpireTimeSpan = TimeSpan.FromDays(14), // Only do this for demo!! AllowInsecureHttp = true }; // Token Generation app.UseOAuthAuthorizationServer(OAuthOptions); app.UseOAuthBearerAuthentication(OAuthBearerOptions); }
public void ConfigureOAuth(IAppBuilder app) { //use a cookie to temporarily store information about a user logging in with a third party login provider //app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie); OAuthBearerOptions = new OAuthBearerAuthenticationOptions() { }; var provider = DependencyConfig.Container.GetInstance(typeof(AuthorizationServerProvider)) as AuthorizationServerProvider; var refreshTokenProvider = DependencyConfig.Container.GetInstance(typeof(RefreshTokenProvider)) as RefreshTokenProvider; OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions() { AllowInsecureHttp = true, TokenEndpointPath = new PathString("/token"), AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(480), Provider = provider, //new AuthorizationServerProvider(), RefreshTokenProvider = refreshTokenProvider //new RefreshTokenProvider() }; // Token Generation app.UseOAuthAuthorizationServer(OAuthServerOptions); app.UseOAuthBearerAuthentication(OAuthBearerOptions); }
public void ConfigureOAuth(IAppBuilder app) { //use a cookie to temporarily store information about a user logging in with a third party login provider app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie); OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions() { AllowInsecureHttp = true, TokenEndpointPath = new PathString("/token"), AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30), Provider = new SimpleAuthorizationServerProvider(), RefreshTokenProvider = new SimpleRefreshTokenProvider() }; // Token Generation app.UseOAuthAuthorizationServer(OAuthServerOptions); app.UseOAuthBearerAuthentication(OAuthBearerOptions); app.UseHealthGraphAuthentication(new HealthGraphAuthenticationOptions { ClientId = "", //TODO: fill own Runkeeper API keys ClientSecret = "" }); }
/// <summary> /// Configurations the o authentication. /// </summary> /// <param name="app">The application.</param> public void ConfigOAuth(IAppBuilder app) { //use a cookie to temporarily store information about a user logging in with a third party login provider app.SetDefaultSignInAsAuthenticationType("ExternalCookie"); OAuthBearerOptions = new OAuthBearerAuthenticationOptions { AuthenticationMode = AuthenticationMode.Active, AuthenticationType = "Bearer", Provider = new OAuthBearerTokenProvider() }; OAuthServerOptions = new OAuthAuthorizationServerOptions { AllowInsecureHttp = true, TokenEndpointPath = new PathString("/Token"), AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"), AccessTokenExpireTimeSpan = TimeSpan.FromDays(15), //Token expiration => The user will remain authenticated for 14 days Provider = new ApplicationOAuthProvider() }; // Enable the application to use bearer tokens to authenticate users // Enabling 3 components: // 1. Authorization Server middleware. For creating the bearer tokens // 2. Application bearer token middleware. Will atuthenticate every request with Authorization : Bearer header // 3. External bearer token middleware. For external providers app.UseOAuthAuthorizationServer(OAuthServerOptions); //app.UseOAuthBearerTokens(OAuthServerOptions, OAuthServerOptions.AuthenticationType); app.UseOAuthBearerAuthentication(OAuthBearerOptions); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = OAuthBearerOptions.AuthenticationType, AuthenticationMode = AuthenticationMode.Active }); }
private void ConfigureAuth(IAppBuilder app) { app.CreatePerOwinContext(AppDbContext.Create); app.CreatePerOwinContext <AppUserManager>(AppUserManager.Create); app.CreatePerOwinContext <AppRoleManager>(AppRoleManager.Create); OAuthAuthorizationServerOptions oAuthServerOptions = new OAuthAuthorizationServerOptions() { AllowInsecureHttp = true, TokenEndpointPath = new PathString("/token"), AccessTokenExpireTimeSpan = TimeSpan.FromDays(1), Provider = new AppAuthorizationServerProvider() }; app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie); OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); GoogleAuthOptions = new GoogleOAuth2AuthenticationOptions { ClientId = "762577690085-8q5b7s18bmdfjel6h8ihcc14tmongbd2.apps.googleusercontent.com", ClientSecret = "MuYGSdOcr5suTwYiUjOrh_52", Provider = new GoogleAuthProvider() }; app.UseGoogleAuthentication(GoogleAuthOptions); FacebookAuthOptions = new FacebookAuthenticationOptions { AppId = "1540544966219959", AppSecret = "afd3895f4a0dd8dc179f7d8a62ece758", Provider = new FacebookAuthProvider() }; app.UseFacebookAuthentication(FacebookAuthOptions); app.UseOAuthAuthorizationServer(oAuthServerOptions); app.UseOAuthBearerAuthentication(OAuthBearerOptions); }
public static void OAuthConfiguration(IAppBuilder appBuilder, IAuthManager authManager, bool allowInsecureHttp = true, string tokenEndpointPath = "/token", TimeSpan?accessTokenExpireTimeSpan = null) { var oAuthServerOptions = new OAuthAuthorizationServerOptions() { AllowInsecureHttp = allowInsecureHttp, TokenEndpointPath = new PathString(tokenEndpointPath), AccessTokenExpireTimeSpan = accessTokenExpireTimeSpan ?? TimeSpan.FromDays(1), Provider = new OAuthAuthorizationServerProvider(authManager), }; var oAuthBearerOptions = new OAuthBearerAuthenticationOptions() { Provider = new OAuthBearerAuthenticationProvider() }; // Token Generation appBuilder.UseOAuthAuthorizationServer(oAuthServerOptions); appBuilder.UseOAuthBearerAuthentication(oAuthBearerOptions); appBuilder.UseAesDataProtectorProvider(); }
private void ConfigureOAuth(IAppBuilder app) { app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie); OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); OAuthAuthorizationServerOptions oAuthServerOptions = new OAuthAuthorizationServerOptions() { AllowInsecureHttp = true, TokenEndpointPath = new PathString("/token"), AccessTokenExpireTimeSpan = TimeSpan.FromDays(1), Provider = new SimpleAuthorizationServerProvider(new AccountRepository()) }; GoogleAuthOptions = new GoogleOAuth2AuthenticationOptions() { ClientId = "592613624399-a3gr6vveaocnptgvv6738rmnk0pb5cev.apps.googleusercontent.com", ClientSecret = "FqNKKib_BP7dsNYBoJa8NwUC", Provider = new GoogleAuthProvider() }; app.UseGoogleAuthentication(GoogleAuthOptions); FacebookAuthOptions = new FacebookAuthenticationOptions() { AppId = "806191272841558", AppSecret = "1a8241e9d46c4a5e393ae51f265a3489", Provider = new FacebookAuthProvider() }; app.UseFacebookAuthentication(FacebookAuthOptions); // Token Generation app.UseOAuthAuthorizationServer(oAuthServerOptions); app.UseOAuthBearerAuthentication(OAuthBearerOptions); }
private void ConfigureOAuth(IAppBuilder app) { OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); //Token Consumption app.UseOAuthBearerAuthentication(OAuthBearerOptions); }
public TrendyolWebApiBuilder WithOAuth(OAuthBearerAuthenticationOptions oAuthBearerAuthenticationOptions) { _appBuilder.BeforeBuild(() => { _owinBuilder.UseOAuthBearerAuthentication(oAuthBearerAuthenticationOptions); }); return this; }
public void ConfigureOAuth(IAppBuilder app) { app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie); OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions() { AllowInsecureHttp = true, TokenEndpointPath = new PathString("/token"), AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"), AccessTokenExpireTimeSpan = TimeSpan.FromHours(24), Provider = new SimpleAuthorizationServerProvider(), RefreshTokenProvider = new SimpleRefreshTokenProvider() }; // Token Generation app.UseOAuthAuthorizationServer(OAuthServerOptions); app.UseOAuthBearerAuthentication(OAuthBearerOptions); KaribouAlpha.DAL.KaribouAlphaContext db = new DAL.KaribouAlphaContext(); LinkedInAuthClient linkedInAuthClient = db.LinkedInAuthClients.SingleOrDefault(_linked => _linked.Active); if (linkedInAuthClient != null) { ILinkedInAuthenticationProvider providerLnk = new KaribouAlpha.Authentication.LinkedInAuthenticationProvider(); LinkedInAuthenticationOptions = new LinkedInAuthenticationOptions() { ClientId = linkedInAuthClient.ClientId, ClientSecret = linkedInAuthClient.ClientSecret, Provider = providerLnk, CallbackPath = new PathString("/AuthCallBack."), Scope = { "r_basicprofile", "r_emailaddress" }, //BackchannelHttpHandler = new LinkedInBackChannelHandler() }; } //http://www.c-sharpcorner.com/article/implementing-oauth2-0-authorization-for-google-in-asp-net/ //https://developers.google.com/actions/identity/oauth2-code-flow GoogleAuthClient googleClient = db.GoogleAuthClients.SingleOrDefault(_google => _google.Active); if (googleClient != null) { GoogleAuthProvider gProvider = new GoogleAuthProvider(); googleAuthOptions = new GoogleOAuth2AuthenticationOptions() { ClientId = googleClient.ClientId, ClientSecret = googleClient.ClientSecret, Provider = gProvider }; } KaribouAlpha.Models.FaceBookClient clientFb = db.FaceBookClients.SingleOrDefault(_fb => _fb.Active); if (clientFb != null) { var fbProvider = new FacebookAuthProvider(); var facebookAuthOptions = new FacebookAuthenticationOptions() { AppId = clientFb.AppId, AppSecret = clientFb.AppSecret, Provider = fbProvider, }; app.UseFacebookAuthentication(facebookAuthOptions); } }
internal static Lazy <OAuthBearerAuthenticationOptions> ConfigureLocalValidation(IdentityServerBearerTokenAuthenticationOptions options, ILoggerFactory loggerFactory) { return(new Lazy <OAuthBearerAuthenticationOptions>(() => { JwtFormat tokenFormat = null; // use static configuration if (!string.IsNullOrWhiteSpace(options.IssuerName) && options.SigningCertificate != null) { // IdSrv3 hard-codes the value when issuing a token using the pattern below var audience = options.IssuerName.EnsureTrailingSlash() + "resources"; // Use the configured values if present, otherwise fallback to the defaulted value List <string> validAudiences; if (options.ValidAudiences != null && options.ValidAudiences.Count() > 0) { validAudiences = new List <string>(options.ValidAudiences); } else { validAudiences = new List <string>() { audience } }; var valParams = new TokenValidationParameters { ValidIssuer = options.IssuerName, ValidAudiences = validAudiences, ValidateAudience = true, IssuerSigningKey = new X509SecurityKey(options.SigningCertificate), NameClaimType = options.NameClaimType, RoleClaimType = options.RoleClaimType, }; tokenFormat = new JwtFormat(valParams); } else { // use discovery endpoint if (string.IsNullOrWhiteSpace(options.Authority)) { throw new Exception("Either set IssuerName and SigningCertificate - or Authority"); } var discoveryEndpoint = options.Authority.EnsureTrailingSlash(); discoveryEndpoint += ".well-known/openid-configuration"; var issuerProvider = new DiscoveryDocumentIssuerSecurityTokenProvider( discoveryEndpoint, options, loggerFactory); // Use the configured values if present, otherwise fallback to the discovery document's value // (which is actually hard-coded to _issuer + "/resources") List <string> validAudiences; if (options.ValidAudiences != null && options.ValidAudiences.Count() > 0) { validAudiences = new List <string>(options.ValidAudiences); } else { validAudiences = new List <string>() { issuerProvider.Audience } }; var valParams = new TokenValidationParameters { ValidAudiences = validAudiences, ValidateAudience = true, NameClaimType = options.NameClaimType, RoleClaimType = options.RoleClaimType }; if (options.IssuerSigningKeyResolver != null) { valParams.IssuerSigningKeyResolver = options.IssuerSigningKeyResolver; } else { valParams.IssuerSigningKeyResolver = IssuerSigningKeyResolver; } tokenFormat = new JwtFormat(valParams, issuerProvider); } var bearerOptions = new OAuthBearerAuthenticationOptions { AccessTokenFormat = tokenFormat, AuthenticationMode = options.AuthenticationMode, AuthenticationType = options.AuthenticationType, Provider = new ContextTokenProvider(options.TokenProvider) }; return bearerOptions; }, LazyThreadSafetyMode.PublicationOnly)); }
internal static Lazy <OAuthBearerAuthenticationOptions> ConfigureLocalValidation(IdentityServerBearerTokenAuthenticationOptions options, ILoggerFactory loggerFactory) { return(new Lazy <OAuthBearerAuthenticationOptions>(() => { JwtFormat tokenFormat = null; // use static configuration if (!string.IsNullOrWhiteSpace(options.IssuerName) && options.SigningCertificate != null) { var audience = options.IssuerName.EnsureTrailingSlash(); audience += "resources"; var valParams = new TokenValidationParameters { ValidIssuer = options.IssuerName, ValidAudience = audience, IssuerSigningKey = new X509SecurityKey(options.SigningCertificate), NameClaimType = options.NameClaimType, RoleClaimType = options.RoleClaimType, }; tokenFormat = new JwtFormat(valParams); } else { // use discovery endpoint if (string.IsNullOrWhiteSpace(options.Authority)) { throw new Exception("Either set IssuerName and SigningCertificate - or Authority"); } var discoveryEndpoint = options.Authority.EnsureTrailingSlash(); discoveryEndpoint += ".well-known/openid-configuration"; var issuerProvider = new DiscoveryDocumentIssuerSecurityTokenProvider( discoveryEndpoint, options, loggerFactory); var valParams = new TokenValidationParameters { ValidAudience = issuerProvider.Audience, NameClaimType = options.NameClaimType, RoleClaimType = options.RoleClaimType }; if (options.IssuerSigningKeyResolver != null) { valParams.IssuerSigningKeyResolver = options.IssuerSigningKeyResolver; } else { valParams.IssuerSigningKeyResolver = ResolveRsaKeys; } tokenFormat = new JwtFormat(valParams, issuerProvider); } var bearerOptions = new OAuthBearerAuthenticationOptions { AccessTokenFormat = tokenFormat, AuthenticationMode = options.AuthenticationMode, AuthenticationType = options.AuthenticationType, Provider = new ContextTokenProvider(options.TokenProvider) }; return bearerOptions; }, LazyThreadSafetyMode.PublicationOnly)); }
public static IAppBuilder UseOAuthBearerAuthentication(this IAppBuilder app, OAuthBearerAuthenticationOptions options) { app.Use(typeof(OAuthBearerAuthenticationMiddleware), app, options); app.UseStageMarkerAuthenticate(); return(app); }
public static void ConfigureAuth(IAppBuilder app) { // Configure the db context, user manager and signin manager to use a single instance per request app.CreatePerOwinContext(ModelDb.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("/member/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, Users>( 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); 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 }; // app.UseOAuthBearerTokens(OAuthOptions); app.UseOAuthAuthorizationServer(OAuthOptions); OAuthBearerOptions = new OAuthBearerAuthenticationOptions() { Provider = new OAuthBearerAuthenticationProvider() }; app.UseOAuthBearerAuthentication(OAuthBearerOptions); //app.UseMicrosoftAccountAuthentication( // clientId: "", // clientSecret: ""); //app.UseTwitterAuthentication( // consumerKey: "", // consumerSecret: ""); //app.UseFacebookAuthentication( // appId: "", // appSecret: ""); //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() //{ // ClientId = "", // ClientSecret = "" //}); }
// 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 OAuth token based authentication OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); app.UseOAuthBearerAuthentication(OAuthBearerOptions); // 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"), ExpireTimeSpan = TimeSpan.FromHours(4.0), Provider = new CookieAuthenticationProvider { OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>( validateInterval: TimeSpan.FromMinutes(30), regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)) } }); app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); ModelMetadataProviders.Current = new CustomModelMetadataProvider(); // Uncomment the following lines to enable logging in with third party login providers //app.UseMicrosoftAccountAuthentication( // clientId: "", // clientSecret: ""); //app.UseTwitterAuthentication( // consumerKey: "", // consumerSecret: ""); // Facebook const string XmlSchemaString = "http://www.w3.org/2001/XMLSchema#string"; var facebookOptions = new Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions { // AppId and AppSecret now stored per instance in web.config. AppId = ConfigurationManager.AppSettings["fbAppId"], AppSecret = ConfigurationManager.AppSettings["fbAppSecret"], Provider = new Microsoft.Owin.Security.Facebook.FacebookAuthenticationProvider { OnAuthenticated = (context) => { context.Identity.AddClaim(new System.Security.Claims.Claim("urn:facebook:access_token", context.AccessToken, XmlSchemaString, "Facebook")); foreach (var x in context.User) { var claimType = string.Format("urn:facebook:{0}", x.Key); string claimValue = x.Value.ToString(); if (!context.Identity.HasClaim(claimType, claimValue)) { context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, XmlSchemaString, "Facebook")); } } return(Task.FromResult(0)); } } }; //Way to specify additional scopes facebookOptions.Scope.Add("email"); app.UseFacebookAuthentication(facebookOptions); //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() //{ // ClientId = "", // ClientSecret = "" //}); }
internal static Lazy<OAuthBearerAuthenticationOptions> ConfigureLocalValidation(IdentityServerBearerTokenAuthenticationOptions options, ILoggerFactory loggerFactory) { return new Lazy<OAuthBearerAuthenticationOptions>(() => { JwtFormat tokenFormat = null; // use static configuration if (!string.IsNullOrWhiteSpace(options.IssuerName) && options.SigningCertificate != null) { var audience = options.IssuerName.EnsureTrailingSlash(); audience += "resources"; var valParams = new TokenValidationParameters { ValidIssuer = options.IssuerName, ValidAudience = audience, IssuerSigningToken = new X509SecurityToken(options.SigningCertificate), NameClaimType = options.NameClaimType, RoleClaimType = options.RoleClaimType, }; tokenFormat = new JwtFormat(valParams); } else { // use discovery endpoint if (string.IsNullOrWhiteSpace(options.Authority)) { throw new Exception("Either set IssuerName and SigningCertificate - or Authority"); } var discoveryEndpoint = options.Authority.EnsureTrailingSlash(); discoveryEndpoint += ".well-known/openid-configuration"; var issuerProvider = new DiscoveryDocumentIssuerSecurityTokenProvider( discoveryEndpoint, options, loggerFactory); var valParams = new TokenValidationParameters { ValidAudience = issuerProvider.Audience, NameClaimType = options.NameClaimType, RoleClaimType = options.RoleClaimType }; tokenFormat = new JwtFormat(valParams, issuerProvider); } var bearerOptions = new OAuthBearerAuthenticationOptions { AccessTokenFormat = tokenFormat, AuthenticationMode = options.AuthenticationMode, AuthenticationType = options.AuthenticationType, Provider = new ContextTokenProvider(options.TokenProvider) }; return bearerOptions; }, true); }
public OAuth2TestServer(Action <OAuth2TestServer> configure = null) { var clock = new TestClock(); Options = new OAuthAuthorizationServerOptions { AuthorizeEndpointPath = new PathString("/authorize"), TokenEndpointPath = new PathString("/token"), Provider = new OAuthAuthorizationServerProvider { OnGrantAuthorizationCode = ctx => { if (ctx.Ticket != null && ctx.Ticket.Identity != null && ctx.Ticket.Identity.IsAuthenticated) { ctx.Validated(); } return(Task.FromResult(0)); }, OnGrantRefreshToken = ctx => { if (ctx.Ticket != null && ctx.Ticket.Identity != null && ctx.Ticket.Identity.IsAuthenticated) { ctx.Validated(); } return(Task.FromResult(0)); }, OnValidateClientRedirectUri = ctx => { if (ctx.ClientId == "alpha") { ctx.Validated("https://gamma.com/return"); } else if (ctx.ClientId == "alpha2") { ctx.Validated("https://gamma2.com/return"); } else if (ctx.ClientId == "alpha3") { ctx.Validated("https://gamma3.com/return"); } return(Task.FromResult(0)); }, OnValidateClientAuthentication = ctx => { string clientId; string clientSecret; if (ctx.TryGetBasicCredentials(out clientId, out clientSecret) || ctx.TryGetFormCredentials(out clientId, out clientSecret)) { if (clientId == "alpha" && clientSecret == "beta") { ctx.Validated(); } else if (clientId == "alpha2" && clientSecret == "beta2") { ctx.Validated(); } else if (clientId == "alpha3" && String.IsNullOrEmpty(clientSecret)) { ctx.Validated(); } } return(Task.FromResult(0)); } }, AuthorizationCodeProvider = new InMemorySingleUseReferenceProvider(), SystemClock = clock, }; BearerOptions = new OAuthBearerAuthenticationOptions { Provider = new OAuthBearerAuthenticationProvider(), AccessTokenProvider = Options.AccessTokenProvider, SystemClock = clock, }; if (configure != null) { configure(this); } Configure(app => { app.Properties["host.AppName"] = "Microsoft.Owin.Security.Tests"; app.UseOAuthBearerAuthentication(BearerOptions); app.UseOAuthAuthorizationServer(Options); app.Use(async(ctx, next) => { if (ctx.Request.Path == Options.AuthorizeEndpointPath && OnAuthorizeEndpoint != null) { await OnAuthorizeEndpoint(ctx); } else if (ctx.Request.Path == new PathString("/testpath") && OnTestpathEndpoint != null) { await OnTestpathEndpoint(ctx); } else if (ctx.Request.Path == new PathString("/me")) { await MeEndpoint(ctx); } else { await next(); } }); }); }
private static Lazy<OAuthBearerAuthenticationOptions> ConfigureEndpointValidation(IdentityServerBearerTokenAuthenticationOptions options, ILoggerFactory loggerFactory) { return new Lazy<OAuthBearerAuthenticationOptions>(() => { if (options.EnableValidationResultCache) { if (options.ValidationResultCache == null) { options.ValidationResultCache = new InMemoryValidationResultCache(options); } } var bearerOptions = new OAuthBearerAuthenticationOptions { AuthenticationMode = options.AuthenticationMode, AuthenticationType = options.AuthenticationType, Provider = new ContextTokenProvider(options.TokenProvider), }; if (!string.IsNullOrEmpty(options.ClientId) || options.IntrospectionHttpHandler != null) { bearerOptions.AccessTokenProvider = new IntrospectionEndpointTokenProvider(options, loggerFactory); } else { bearerOptions.AccessTokenProvider = new ValidationEndpointTokenProvider(options, loggerFactory); } return bearerOptions; }, true); }
static Startup() { OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); }
// 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 //}; //// Enable the application to use bearer tokens to authenticate users //app.UseOAuthBearerTokens(OAuthOptions); // 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 = "" //}); // This must come first to intercept the /Token requests app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll); var oauthServerConfig = new OAuthAuthorizationServerOptions { AllowInsecureHttp = AuthenticationConstants.AllowInsecureHttp, TokenEndpointPath = new PathString("/token"), AccessTokenExpireTimeSpan = SecurityTokenConstants.TokenLifeTime, Provider = new MembershipRebootOAuthAuthorizationServerProvider(), RefreshTokenProvider = new MembershipRebootOAuthAuthorizationServerRefreshTokenProvider() }; app.UseOAuthAuthorizationServer(oauthServerConfig); var oauthConfig = new OAuthBearerAuthenticationOptions { AuthenticationMode = AuthenticationMode.Active, AuthenticationType = AuthenticationConstants.BearerAuthType }; app.UseOAuthBearerAuthentication(oauthConfig); app.UseBasicAuthentication(new BasicAuthenticationOptions("qssolutions.net", UserAccountServiceFactory.Create()) { AuthenticationType = AuthenticationConstants.BasicAuthType, AuthenticationMode = AuthenticationMode.Active }); }
static AccountController() { OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); }
private void UseOAuthSecurity(IAppBuilder app) { // Todo: Add this only when relaying is enabled (no need to auth OnPremises if not), and add // a second endpoint with different token lifetime for management web user (i.e. `/managementToken`), // when management web is enabled. Also, use different AuthProviders for each endpoint var serverOptions = new OAuthAuthorizationServerOptions { AllowInsecureHttp = _configuration.UseInsecureHttp, TokenEndpointPath = new PathString("/token"), AccessTokenExpireTimeSpan = _configuration.AccessTokenLifetime, Provider = _authorizationServerProvider, }; var certBase64 = _configuration.OAuthCertificate; if (!String.IsNullOrWhiteSpace(certBase64)) { var cert = new X509Certificate2(Convert.FromBase64String(certBase64)); serverOptions.AccessTokenFormat = new TicketDataFormat(new RsaDataProtector(cert)); var authOptions = new OAuthBearerAuthenticationOptions { AccessTokenFormat = new TicketDataFormat(new RsaDataProtector(cert)), Provider = new OAuthBearerAuthenticationProvider() { OnApplyChallenge = context => { // Workaround: Keep an already set WWW-Authenticate header (otherwise OWIN would add its challenge). if (!context.Response.Headers.ContainsKey("WWW-Authenticate")) { context.OwinContext.Response.Headers.AppendValues("WWW-Authenticate", context.Challenge); } return(Task.CompletedTask); } } }; app.UseOAuthBearerAuthentication(authOptions); } else { var sharedSecret = _configuration.SharedSecret; if (!String.IsNullOrWhiteSpace(sharedSecret)) { const string issuer = "http://thinktecture.com/relayserver/sts"; const string audience = "http://thinktecture.com/relayserver/consumers"; var key = Convert.FromBase64String(sharedSecret); serverOptions.AccessTokenFormat = new CustomJwtFormat(serverOptions.AccessTokenExpireTimeSpan, key, issuer, audience); app.UseJwtBearerAuthentication(new JwtBearerAuthenticationOptions() { AllowedAudiences = new[] { audience }, IssuerSecurityTokenProviders = new[] { new SymmetricKeyIssuerSecurityTokenProvider(issuer, key) }, }); } } app.UseOAuthAuthorizationServer(serverOptions); }