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); //Bearer authentication init OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); app.UseOAuthBearerAuthentication(OAuthBearerOptions); #region Google authentication configurations GoogleAuthOptions = new GoogleOAuth2AuthenticationOptions() { ClientId = ConfigurationManager.AppSettings["authConfig:GoogleClientId"], ClientSecret = ConfigurationManager.AppSettings["authConfig:GoogleClientSecret"], Provider = new GoogleAuthProvider() }; app.UseGoogleAuthentication(GoogleAuthOptions); #endregion #region Twitter authentication configurations TwitterAuthOptions = new TwitterAuthenticationOptions() { ConsumerKey = ConfigurationManager.AppSettings["authConfig:TwitterConsumerKey"], ConsumerSecret = ConfigurationManager.AppSettings["authConfig:TwitterConsumerSecret"], Provider = new TwitterAuthProvider(), BackchannelCertificateValidator = new CertificateSubjectKeyIdentifierValidator(new[] { "A5EF0B11CEC04103A34A659048B21CE0572D7D47", // VeriSign Class 3 Secure Server CA - G2 "0D445C165344C1827E1D20AB25F40163D8BE79A5", // VeriSign Class 3 Secure Server CA - G3 "7FD365A7C2DDECBBF03009F34339FA02AF333133", // VeriSign Class 3 Public Primary Certification Authority - G5 "39A55D933676616E73A761DFA16A7E59CDE66FAD", // Symantec Class 3 Secure Server CA - G4 "5168FF90AF0207753CCCD9656462A212B859723B", //DigiCert SHA2 High Assurance Server CA "B13EC36903F8BF4701D498261A0802EF63642BC3" //DigiCert High Assurance EV Root CA }) }; app.UseTwitterAuthentication(TwitterAuthOptions); #endregion #region Vkontakte authentication configurations VkontakteAuthOptions = new VkAuthenticationOptions() { ClientId = ConfigurationManager.AppSettings["authConfig:VkontakteClientId"], ClientSecret = ConfigurationManager.AppSettings["authConfig:VkontakteClientSecret"], Scope = new List <string>() { "email" }, Provider = new VkontakteAuthProvider() }; app.UseVkontakteAuthentication(VkontakteAuthOptions); #endregion }
/// <summary> /// Authenticate users using Vkontakte /// </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 UseVkontakteAuthentication(this IAppBuilder app, VkAuthenticationOptions options) { if (app == null) { throw new ArgumentNullException("app"); } if (options == null) { throw new ArgumentNullException("options"); } app.Use(typeof(VkAuthenticationMiddleware), app, options); return(app); }
/// <summary> /// </summary> /// <param name="appBuilder"></param> /// <param name="settings"></param> public override void ConfigureMiddleware(IAppBuilder appBuilder, ServiceSettingsDictionary settings) { var options = new VkAuthenticationOptions { ClientId = Environment.GetEnvironmentVariable("VKClientId"), ClientSecret = Environment.GetEnvironmentVariable("VKClientSecret"), Provider = new VKLoginAuthenticationProvider(), AuthenticationType = Name, Scope = { "email" } }; appBuilder.UseVkontakteAuthentication(options); }
public void Configuration(IAppBuilder app) { app.CreatePerOwinContext <AppIdentityDbContext>(AppIdentityDbContext.Create); app.CreatePerOwinContext <AppUserManager>(AppUserManager.Create); //app.CreatePerOwinContext<AppRoleManager>(AppRoleManager.Create); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login"), }); app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions { ClientId = "67606520237-5vvmm7gsu7s0d6kiuvuf6vcbqmkpd1md.apps.googleusercontent.com", ClientSecret = "vx1SwjY4hZC6W6fzS8oVOuUl", }; app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions); var vkontakteAuthentication = new VkAuthenticationOptions { AppId = "5687489", AppSecret = "ZGkOJrq3VCXzADho9Leh", Scope = "friends, status, wall, groups, photo", Provider = new VkAuthenticationProvider() { OnAuthenticated = async context => { context.Identity.AddClaim(new System.Security.Claims.Claim("VkontakteAccessToken", context.AccessToken)); // Retrieve the OAuth access token to store for subsequent API calls //var accessToken = context.AccessToken; // Retrieve the username //var vkontakteName = context.UserName; //return Task.FromResult(0); } } }; vkontakteAuthentication.SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie; app.UseVkontakteAuthentication(vkontakteAuthentication); }