本文整理汇总了C#中IAppBuilder.UseOAuthBearerTokens方法的典型用法代码示例。如果您正苦于以下问题:C# IAppBuilder.UseOAuthBearerTokens方法的具体用法?C# IAppBuilder.UseOAuthBearerTokens怎么用?C# IAppBuilder.UseOAuthBearerTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAppBuilder
的用法示例。
在下文中一共展示了IAppBuilder.UseOAuthBearerTokens方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureAuth
public void ConfigureAuth(IAppBuilder app)
{
app.CreatePerOwinContext<IdentityUserManager>(IdentityUserManager.Create);
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
PublicClientId = "self";
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/OAuth/Token"),
Provider = new ApplicationOAuthProvider(PublicClientId),
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(5),
AllowInsecureHttp = true
};
app.UseOAuthBearerTokens(OAuthOptions);
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
//app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
//{
// ClientId = "852925537385-9t4d8fg869kpi1dlm58v77277b70lc6e.apps.googleusercontent.com",
// ClientSecret = "078iMDZvE2JKYZc8-a5TeEey",
// Provider = new GoogleAuthProvider()
//});
}
示例2: Configuration
public void Configuration(IAppBuilder app)
{
// アプリケーションの設定方法の詳細については、http://go.microsoft.com/fwlink/?LinkID=316888 を参照してください
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
// アプリケーションが Cookie を使用して、サインインしたユーザーの情報を格納できるようにします
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, UserAccount>(
validateInterval: TimeSpan.FromMinutes(20),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
// サード パーティのログイン プロバイダーを使用してログインしているユーザーに関する情報を一時的に格納するのに Cookie を使用します
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// アプリケーションがベアラ トークンを使用してユーザーを認証できるようにします
app.UseOAuthBearerTokens(OAuthOptions);
OAuthAuthenticationConfiguratorManager.ConfigureOAuthentication(app);
}
示例3: ConfigureAuth
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
app.UseCors(new CorsOptions {PolicyProvider = new CustomOwinCorsPolicyProvider()});
// 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: ConfigurationManager.AppSettings.Get("OAuthMicrosoftKey"),
clientSecret: ConfigurationManager.AppSettings.Get("OAuthMicrosoftSecret"));
app.UseTwitterAuthentication(
consumerKey: ConfigurationManager.AppSettings.Get("OAuthTwitterKey"),
consumerSecret: ConfigurationManager.AppSettings.Get("OAuthTwitterSecret"));
app.UseFacebookAuthentication(
appId: ConfigurationManager.AppSettings.Get("OAuthFacebookKey"),
appSecret: ConfigurationManager.AppSettings.Get("OAuthFacebookSecret"));
app.UseGoogleAuthentication();
}
示例4: ConfigureAuth
// 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),
// In production mode set AllowInsecureHttp = false
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(
// new TwitterAuthenticationOptions
// {
// ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"],
// ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"],
// BackchannelCertificateValidator = new Microsoft.Owin.Security.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
// "4eb6d578499b1ccf5f581ead56be3d9b6744a5e5", // VeriSign Class 3 Primary CA - G5
// "5168FF90AF0207753CCCD9656462A212B859723B", // DigiCert SHA2 High Assurance Server CA
// "B13EC36903F8BF4701D498261A0802EF63642BC3" // DigiCert High Assurance EV Root CA
// })
// }
// );
//app.UseFacebookAuthentication(
// appId: "",
// appSecret: "");
//app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
//{
// ClientId = "",
// ClientSecret = ""
//});
}
示例5: ConfigureAuth
// 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(SkyberryContext.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
{
// access tokens
Provider = new ApplicationOAuthProvider(PublicClientId),
// using short lived access tokens coupled with long lived refresh tokens
AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(60),
AllowInsecureHttp = true,
// refresh tokens
RefreshTokenProvider = new RefreshTokenProvider(),
TokenEndpointPath = new PathString("/token"),
};
// Enable the application to use bearer tokens to authenticate users
app.UseOAuthBearerTokens(OAuthOptions);
}
示例6: ConfigureAuth
public void ConfigureAuth(IAppBuilder app)
{
app.CreatePerOwinContext(() => new EnergyNetworkDbContext());
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);
//Enable Cors support in the Web API. Should go before the activation of Bearer tokens
//http://aspnetwebstack.codeplex.com/discussions/467315
app.UseCors(CorsOptions.AllowAll);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// 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.UseOAuthBearerTokens(OAuthOptions);
app.UseMicrosoftAccountAuthentication(ConfigurationManager.AppSettings["MicrosoftKey"],
ConfigurationManager.AppSettings["MicrosoftSecret"]);
app.UseTwitterAuthentication(ConfigurationManager.AppSettings["TwitterKey"],
ConfigurationManager.AppSettings["TwitterSecret"]);
app.UseFacebookAuthentication(ConfigurationManager.AppSettings["FacebookKey"],
ConfigurationManager.AppSettings["FacebookSecret"]);
app.UseGoogleAuthentication();
}
示例7: ConfigureAuth
// Pour plus d’informations sur la configuration de l’authentification, rendez-vous sur 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);
// Autoriser l’application à utiliser des jetons de support pour authentifier les utilisateurs
app.UseOAuthBearerTokens(OAuthOptions);
// Supprimer les commentaires des lignes suivantes pour autoriser la connexion avec des fournisseurs de connexions tiers
//app.UseMicrosoftAccountAuthentication(
// clientId: "",
// clientSecret: "");
//app.UseTwitterAuthentication(
// consumerKey: "",
// consumerSecret: "");
//app.UseFacebookAuthentication(
// appId: "",
// appSecret: "");
//app.UseGoogleAuthentication();
}
示例8: ConfigureAuth
public static void ConfigureAuth(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Configure the application for OAuth based flow
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
Provider = new ApplicationOAuthProvider("self"),
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
// TODO: In production mode set AllowInsecureHttp = false
AllowInsecureHttp = true
};
// Enable the application to use bearer tokens to authenticate users
app.UseOAuthBearerTokens(OAuthOptions);
// app.UseFacebookAuthentication(
// appId: "",
// appSecret: "");
// app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
// {
// ClientId = "",
// ClientSecret = ""
// });
}
示例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: "000000004C172782",
clientSecret: "9rjrusF64Ws2Ksd67DVgyPgd0101i4jw");
app.UseTwitterAuthentication(
consumerKey: "QBAhakLsIl794uEEAX8csF3tP",
consumerSecret: "ML44lD3gjDWfF1VR2SRmYa8Ic0VPUEk9FwraEBs0iP3awfvKuS");
app.UseFacebookAuthentication(
appId: "523635924470241",
appSecret: "ef29066fd82cb20e746b52c00c7e34a7");
app.UseGoogleAuthentication(new Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions() { ClientId = "122905730574.apps.googleusercontent.com", ClientSecret = "AjLf5P2WiGXIQrKqeTBRifAr" });
}
示例10: ConfigureOAuthTokenGeneration
private void ConfigureOAuthTokenGeneration(IAppBuilder app)
{
// Configure the db context and user manager to use a single instance per request
app.CreatePerOwinContext(InnoventoryDBContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.UseCookieAuthentication(new CookieAuthenticationOptions() { LoginPath = new PathString("/account/login") });
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);
}
示例11: ConfigureAuth
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
// 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 = ""
//});
}
示例12: ConfigureAuth
public void ConfigureAuth(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseCors(CorsOptions.AllowAll);
app.UseOAuthBearerTokens(OAuthOptions);
}
示例13: Configuration
public void Configuration(IAppBuilder app)
{
var unity = UnityConfig.GetConfiguredContainer();
var config = new HttpConfiguration();
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
config.MapHttpAttributeRoutes();
config.DependencyResolver = new UnityDependencyResolver(unity);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseOAuthBearerTokens(new OAuthAuthorizationServerOptions
{
AllowInsecureHttp = true,
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
ApplicationCanDisplayErrors = true,
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
Provider = new OAuthProvider("self", () => unity.Resolve<IUserPasswordStore<User, Guid>>(), unity.Resolve<IPasswordHasher>()),
TokenEndpointPath = new PathString("/Token"),
});
var settings = ConfigurationManager.AppSettings;
app.UseMicrosoftAccountAuthentication(settings.Get("MicrosoftClientId"), settings.Get("MicrosoftClientSecret"))
.UseTwitterAuthentication(settings.Get("TwitterConsumerKey"), settings.Get("TwitterConsumerSecret"))
.UseFacebookAuthentication(settings.Get("FacebookAppId"), settings.Get("FacebookAppSecret"))
.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions
{
ClientId = settings.Get("GoogleClientId"),
ClientSecret = settings.Get("GoogleClientSecret")
});
app.UseWebApi(config);
AutoMapperConfig.Configure();
}
示例14: ConfigureAuth
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
// Configure the application for OAuth based flow
PublicClientId = "self";
OAuthOptions = new OAuthAuthorizationServerOptions
{
Provider = new ApplicationOAuthProvider(PublicClientId),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
// In production mode set AllowInsecureHttp = false
AllowInsecureHttp = true
};
// Enable the application to use bearer tokens to authenticate users
app.UseOAuthBearerTokens(OAuthOptions);
app.UseScopeAuthentication(new ScopeAuthorizationManager());
// 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 = ""
//});
}
示例15: 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);
}