本文整理汇总了C#中Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions类的典型用法代码示例。如果您正苦于以下问题:C# GoogleOAuth2AuthenticationOptions类的具体用法?C# GoogleOAuth2AuthenticationOptions怎么用?C# GoogleOAuth2AuthenticationOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GoogleOAuth2AuthenticationOptions类属于Microsoft.Owin.Security.Google命名空间,在下文中一共展示了GoogleOAuth2AuthenticationOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureOAuth
/// <summary>
/// Se realiza la configuración de autorización
/// </summary>
/// <param name="app"></param>
public void ConfigureOAuth(IAppBuilder app)
{
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(new OAuthBearerAuthenticationOptions());
app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie);
OAuthBearerOptions = new OAuthBearerAuthenticationOptions();
googleAuthOptions = new GoogleOAuth2AuthenticationOptions()
{
ClientId = "185157178718-8qc15td8nefjssrai2md8eiodr151m8u.apps.googleusercontent.com",
ClientSecret = "tmnYb6S99BJPWVbv45Ha8Mf-",
Provider = new GoogleAuthProvider()
};
app.UseGoogleAuthentication(googleAuthOptions);
}
示例2: ConfigureAdditionalIdentityProviders
public static void ConfigureAdditionalIdentityProviders(IAppBuilder app, string signInAsType)
{
var google = new GoogleOAuth2AuthenticationOptions
{
AuthenticationType = "Google",
SignInAsAuthenticationType = signInAsType,
ClientId = "client", //"767400843187-8boio83mb57ruogr9af9ut09fkg56b27.apps.googleusercontent.com",
ClientSecret = "secret" //"5fWcBT0udKY7_b6E3gEiJlze"
};
app.UseGoogleAuthentication(google);
var fb = new FacebookAuthenticationOptions
{
AuthenticationType = "Facebook",
SignInAsAuthenticationType = signInAsType,
AppId = "app", //"676607329068058",
AppSecret = "secret" //"9d6ab75f921942e61fb43a9b1fc25c63"
};
app.UseFacebookAuthentication(fb);
var twitter = new TwitterAuthenticationOptions
{
AuthenticationType = "Twitter",
SignInAsAuthenticationType = signInAsType,
ConsumerKey = "consumer", //"N8r8w7PIepwtZZwtH066kMlmq",
ConsumerSecret = "secret" //"df15L2x6kNI50E4PYcHS0ImBQlcGIt6huET8gQN41VFpUCwNjM"
};
app.UseTwitterAuthentication(twitter);
}
示例3: ConfigureOAuth
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"),
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 = "936007638974-2ko9tqdmv3ifomlblhlrnninkdoe9bkt.apps.googleusercontent.com",
ClientSecret = "4_GR4_4JPnglWQOnSnwOZzlV",
Provider = new GoogleAuthProvider()
};
app.UseGoogleAuthentication(googleAuthOptions);
}
示例4: Configuration
public void Configuration(IAppBuilder app)
{
app.CreatePerOwinContext(AppDbContext.Create);
app.CreatePerOwinContext<AppUserManager>(AppUserManager.Create);
app.CreatePerOwinContext<AppSignInManager>(AppSignInManager.Create);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
//app.Use((context, next) =>
//{
// var identity = context.Authentication.User.Identity as ClaimsIdentity;
// if (identity != null && identity.IsAuthenticated)
// {
// identity.AddClaim(new Claim(ClaimTypes.Role, "admin"));
// }
// return next.Invoke();
//});
var googleOauthOptions = new GoogleOAuth2AuthenticationOptions
{
ClientId = WebConfigurationManager.AppSettings["GoogleClientId"],
ClientSecret = WebConfigurationManager.AppSettings["GoogleClientSecret"],
SignInAsAuthenticationType = app.GetDefaultSignInAsAuthenticationType(), //26.08
Provider = new GoogleOAuth2AuthenticationProvider
{
OnAuthenticated = context =>
{
var accessToken = context.AccessToken;
//var serializedUser = context.User;
//var name = context.Name;
//var gender = serializedUser.Value<string>("gender");
context.Identity.AddClaim(new Claim("urn:google:access_token", accessToken, XmlSchemaString,
"Google"));
//foreach (var keyVal in context.User)
//{
// var claimType = string.Format("urn:google:{0}", keyVal.Key);
// var claimVal = keyVal.Value.ToString();
// if (!context.Identity.HasClaim(claimType, claimVal))
// {
// context.Identity.AddClaim(new Claim(claimType, claimVal,
// XmlSchemaString, "Google"));
// }
//}
return Task.FromResult(0);
}
}
};
googleOauthOptions.Scope.Add("openid");
googleOauthOptions.Scope.Add("profile");
googleOauthOptions.Scope.Add("email");
googleOauthOptions.Scope.Add("https://www.googleapis.com/auth/drive.readonly");
app.UseGoogleAuthentication(googleOauthOptions);
}
示例5: ConfigureAuth
private void ConfigureAuth(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
LoginPath = new PathString("/account/login"),
Provider = new CookieAuthenticationProvider
{
OnApplyRedirect = ctx =>
{
if (!IsApiRequest(ctx.Request))
{
ctx.Response.Redirect(ctx.RedirectUri);
}
}
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
var provider = new GoogleOAuth2AuthenticationProvider();
var options = new GoogleOAuth2AuthenticationOptions
{
ClientId = ConfigurationManager.AppSettings["ClientId"],
ClientSecret = ConfigurationManager.AppSettings["ClientSecret"],
Provider = provider
};
app.UseGoogleAuthentication(options);
}
示例6: ConfigureAuth
// 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
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
// Use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Uncomment the following lines to enable logging in with third party login providers
//app.UseMicrosoftAccountAuthentication(
// clientId: "",
// clientSecret: "");
//app.UseTwitterAuthentication(
// consumerKey: "",
// consumerSecret: "");
app.UseFacebookAuthentication(
appId: "1689954101236608",
appSecret: "676d9b0e35af6af7c46f3a95d81ca796");
var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions
{
ClientId = "611179519995-rj11d6cfr591cvfiqsuh82jqc85ok7s9.apps.googleusercontent.com",
ClientSecret = "NP3DaOGrGMMykrApiQ7QmWox",
};
app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions);
//app.UseGoogleAuthentication();
}
示例7: ConfigureOAuth
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);
}
示例8: Configure
public static void Configure(IAppBuilder app)
{
// Enable the application to use a cookie to store information for the signed in user
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ExternalCookie
});
// Use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Configure google authentication
var options = new GoogleOAuth2AuthenticationOptions()
{
ClientId = "your app client id",
ClientSecret = "your app client secret"
};
app.UseGoogleAuthentication(options);
facebookAuthOptions = new FacebookAuthenticationOptions()
{
AppId = "528982800546743",
AppSecret = "a6ee5ad8448c7c67fcedc72d5a4c501a",
Provider = new FacebookAuthProvider()
};
app.UseFacebookAuthentication(facebookAuthOptions);
}
示例9: ConfigureAuth
// 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);
// Uncomment the following lines to enable logging in with third party login providers
//app.UseMicrosoftAccountAuthentication(
// clientId: "",
// clientSecret: "");
//app.UseTwitterAuthentication(
// consumerKey: "DE9rrDoJOJhbrGR9BBMpyBwa6",
// consumerSecret: "bsO1Wz3qx3kUsSIVk0s1ycIWsekDvR8P33m45CDjoU9Qi6YgY1");
IFacebookAuthenticationFactory facebookAuthenticationFactory = new FacebookAuthenticationFactory();
FacebookAuthenticationOptions facebookAuthenticationOptions = facebookAuthenticationFactory.CreateAuthenticationOptions();
app.UseFacebookAuthentication(facebookAuthenticationOptions);
GoogleOAuth2AuthenticationOptions googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions()
{
ClientId = ConfigurationManager.AppSettings["oAuth2.Google.ClientId"],
ClientSecret = ConfigurationManager.AppSettings["oAuth2.Google.ClientSecret"]
};
googleOAuth2AuthenticationOptions.Scope.Add("profile");
googleOAuth2AuthenticationOptions.Scope.Add("email");
app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions);
}
示例10: ConfigureOAuth
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);
}
示例11: GoogleOAuth2Configuration
public void GoogleOAuth2Configuration(IAppBuilder app)
{
app.UseAuthSignInCookie();
var option = new GoogleOAuth2AuthenticationOptions()
{
ClientId = "581497791735.apps.googleusercontent.com",
ClientSecret = "-N8rQkJ_MKbhpaxyjdVYbFpO",
};
app.UseGoogleAuthentication(option);
app.Run(async context =>
{
if (context.Authentication.User == null || !context.Authentication.User.Identity.IsAuthenticated)
{
var authenticationProperties = new AuthenticationProperties();
authenticationProperties.Dictionary.Add("access_type", "custom_accessType");
authenticationProperties.Dictionary.Add("approval_prompt", "custom_approval_prompt");
authenticationProperties.Dictionary.Add("login_hint", "custom_login_hint");
context.Authentication.Challenge(authenticationProperties, "Google");
await context.Response.WriteAsync("Unauthorized");
}
});
}
示例12: WithGoogleAuthentication
public ExternalIdentityProviderService WithGoogleAuthentication(string clientId, string clientSecret)
{
if (string.IsNullOrWhiteSpace(clientId))
{
throw new ArgumentNullException(nameof(clientId));
}
if (string.IsNullOrEmpty(clientSecret))
{
throw new ArgumentNullException(nameof(clientId));
}
configurators.Add((appBuilder, signInAsType) =>
{
var google = new GoogleOAuth2AuthenticationOptions
{
AuthenticationType = "Google",
SignInAsAuthenticationType = signInAsType,
ClientId = clientId,
ClientSecret = clientSecret
};
appBuilder.UseGoogleAuthentication(google);
});
return this;
}
示例13: ConfigureOAuth
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 = System.Configuration.ConfigurationManager.AppSettings["FacebookAppId"],
AppSecret = System.Configuration.ConfigurationManager.AppSettings["FacebookAppSecret"],
Provider = new FacebookAuthProvider()
};
app.UseFacebookAuthentication(facebookAuthOptions);
//Configure Twitter External Login
twitterAuthOptions = new TwitterAuthenticationOptions()
{
ConsumerKey = System.Configuration.ConfigurationManager.AppSettings["TwitterConsumerKey"],
ConsumerSecret = System.Configuration.ConfigurationManager.AppSettings["TwitterConsumerSecret"],
Provider = new TwitterAuthProvider()
};
app.UseTwitterAuthentication(twitterAuthOptions);
//Configure LinkedIn External Login
linkedinAuthOptions = new LinkedInAuthenticationOptions()
{
ClientId = System.Configuration.ConfigurationManager.AppSettings["LinkedInClientId"],
ClientSecret = System.Configuration.ConfigurationManager.AppSettings["LinkedInSecret"],
Provider = new LinkedInAuthProvider()
};
app.UseLinkedInAuthentication(linkedinAuthOptions);
}
示例14: ConfigureIdentityProviders
public static void ConfigureIdentityProviders(IAppBuilder app, string signInAsType)
{
var google = new GoogleOAuth2AuthenticationOptions
{
AuthenticationType = "Google",
Caption = "Google",
SignInAsAuthenticationType = signInAsType,
ClientId = "767400843187-8boio83mb57ruogr9af9ut09fkg56b27.apps.googleusercontent.com",
ClientSecret = "5fWcBT0udKY7_b6E3gEiJlze"
};
app.UseGoogleAuthentication(google);
var fb = new FacebookAuthenticationOptions
{
AuthenticationType = "Facebook",
Caption = "Facebook",
SignInAsAuthenticationType = signInAsType,
AppId = "676607329068058",
AppSecret = "9d6ab75f921942e61fb43a9b1fc25c63"
};
app.UseFacebookAuthentication(fb);
var twitter = new TwitterAuthenticationOptions
{
AuthenticationType = "Twitter",
Caption = "Twitter",
SignInAsAuthenticationType = signInAsType,
ConsumerKey = "N8r8w7PIepwtZZwtH066kMlmq",
ConsumerSecret = "df15L2x6kNI50E4PYcHS0ImBQlcGIt6huET8gQN41VFpUCwNjM"
};
app.UseTwitterAuthentication(twitter);
//var adfs = new WsFederationAuthenticationOptions
//{
// AuthenticationType = "adfs",
// Caption = "ADFS",
// SignInAsAuthenticationType = signInAsType,
// MetadataAddress = "https://adfs.leastprivilege.vm/federationmetadata/2007-06/federationmetadata.xml",
// Wtrealm = "urn:idsrv3"
//};
//app.UseWsFederationAuthentication(adfs);
var aad = new OpenIdConnectAuthenticationOptions
{
AuthenticationType = "aad",
Caption = "Azure AD",
SignInAsAuthenticationType = signInAsType,
Authority = "https://login.windows.net/4ca9cb4c-5e5f-4be9-b700-c532992a3705",
ClientId = "65bbbda8-8b85-4c9d-81e9-1502330aacba",
RedirectUri = "https://localhost:44333/core/aadcb"
};
app.UseOpenIdConnectAuthentication(aad);
}
示例15: ConfigureAuth
public void ConfigureAuth(IAppBuilder app)
{
// app.CreatePerOwinContext(XcendentAuthContext.Create);
//app.CreatePerOwinContext<XcendentUserManager>(XcendentUserManager.Create);
app.UseCors(CorsOptions.AllowAll);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
PublicClientId = "self";
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
Provider = new XcendentOAuthProvider(PublicClientId),
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
// In production mode set AllowInsecureHttp = false
AllowInsecureHttp = true
};
app.UseOAuthBearerTokens(OAuthOptions);
// Uncomment the following lines to enable logging in with third party login providers
//app.UseMicrosoftAccountAuthentication(
// clientId: "",
// clientSecret: "");
//app.UseTwitterAuthentication(
// consumerKey: "",
// consumerSecret: "");
FacebookAuthenticationOptions facebookAuthOptions = new FacebookAuthenticationOptions()
{
AppId = "553074264845816",
AppSecret = "c71200f8ba3d48f92433c9e1844a7239",
Provider = new FacebookAuthProvider()
};
// facebookAuthOptions.Scope.Clear();
facebookAuthOptions.Scope.Add("public_profile");
facebookAuthOptions.Scope.Add("email");
app.UseFacebookAuthentication(facebookAuthOptions);
GoogleOAuth2AuthenticationOptions googleOptions = new GoogleOAuth2AuthenticationOptions();
googleOptions.Scope.Clear();
googleOptions.Scope.Add("profile");
googleOptions.Scope.Add("email");
googleOptions.ClientId = "141496314941-4bc07d10tkmctlrcb0ealjp0n45d04dl.apps.googleusercontent.com";
googleOptions.ClientSecret = "UWQkdq18I3VB7udh3aBsxOK9";
googleOptions.Provider = new GoogleAuthProvider();
googleOptions.AccessType = "online";
// googleOptions.AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Passive;
app.UseGoogleAuthentication(googleOptions);
}