本文整理汇总了C#中Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationOptions类的典型用法代码示例。如果您正苦于以下问题:C# OAuthBearerAuthenticationOptions类的具体用法?C# OAuthBearerAuthenticationOptions怎么用?C# OAuthBearerAuthenticationOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OAuthBearerAuthenticationOptions类属于Microsoft.Owin.Security.OAuth命名空间,在下文中一共展示了OAuthBearerAuthenticationOptions类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: 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 Facebook External Login
//FacebookAuthOptions = new FacebookAuthenticationOptions()
//{
// AppId = "841670309262660",
// AppSecret = "8b4eba3df30d4aa95427fa9c90372462",
// Provider = new FacebookAuthProvider(),
// Scope = { "user_about_me", "user_friends", "email", "read_friendlists", "publish_stream", "user_birthday", "user_location" }
//};
//app.UseFacebookAuthentication(FacebookAuthOptions);
}
开发者ID:IlyaKazlou,项目名称:PickMeUpGlobal,代码行数:30,代码来源:Startup.cs
示例2: UseWindowsAzureActiveDirectoryBearerAuthentication
/// <summary>
/// Adds Windows Azure Active Directory (WAAD) issued JWT bearer token middleware to your web application pipeline.
/// </summary>
/// <param name="app">The IAppBuilder passed to your configuration method.</param>
/// <param name="options">An options class that controls the middleware behavior.</param>
/// <returns>The original app parameter.</returns>
public static IAppBuilder UseWindowsAzureActiveDirectoryBearerAuthentication(this IAppBuilder app, WindowsAzureActiveDirectoryBearerAuthenticationOptions options)
{
if (options == null)
{
throw new ArgumentNullException("options");
}
if (string.IsNullOrWhiteSpace(options.Tenant))
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, "Tenant"));
}
var bearerOptions = new OAuthBearerAuthenticationOptions
{
Realm = options.Realm,
Provider = options.Provider,
AccessTokenFormat = new JwtFormat(options.Audience,
new WsFedCachingSecurityTokenProvider(
string.Format(CultureInfo.InvariantCulture, SecurityTokenServiceAddressFormat, options.Tenant),
options.BackchannelCertificateValidator, options.BackchannelTimeout, options.BackchannelHttpHandler)),
AuthenticationMode = options.AuthenticationMode,
AuthenticationType = options.AuthenticationType,
Description = options.Description
};
app.UseOAuthBearerAuthentication(bearerOptions);
return app;
}
开发者ID:ricardodemauro,项目名称:katana-clone,代码行数:34,代码来源:WindowsAzureActiveDirectoryBearerAuthenticationExtensions.cs
示例3: Configuration
public void Configuration(IAppBuilder app)
{
SecurityConfig.Config();
var oauthServerConfig = new Microsoft.Owin.Security.OAuth.OAuthAuthorizationServerOptions
{
AllowInsecureHttp = false,
AccessTokenExpireTimeSpan = TimeSpan.FromHours(2),
Provider = new AuthorizationServerProvider(),
TokenEndpointPath = new PathString("/token")
};
app.UseOAuthAuthorizationServer(oauthServerConfig);
var oauthConfig = new Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationOptions
{
AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active
//AuthenticationType = "Bearer"
};
app.UseOAuthBearerAuthentication(oauthConfig);
var config = new HttpConfiguration();
WebApiConfig.Register(config);
app.UseWebApi(config);
GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(1);
GlobalHost.Configuration.LongPollDelay = TimeSpan.FromMilliseconds(5000);
app.MapSignalR();
}
开发者ID:jmptrader,项目名称:WebFrameworkSPA,代码行数:25,代码来源:Startup.cs
示例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
};
// Token Generation
app.UseOAuthAuthorizationServer(OAuthOptions);
OAuthBearerOptions = new OAuthBearerAuthenticationOptions();
app.UseOAuthBearerAuthentication(OAuthBearerOptions);
facebookAuthOptions = new FacebookAuthenticationOptions
{
AppId = "1543886725935090",
AppSecret = "63ab7a49e991177caf72e3ec8f2247cc",
Provider = new FacebookAuthProvider()
};
app.UseFacebookAuthentication(facebookAuthOptions);
}
开发者ID:DarkNormal,项目名称:PosseNetAPIApp,代码行数:36,代码来源:Startup.Auth.cs
示例5: ConfigureOAuth
public void ConfigureOAuth(IAppBuilder app)
{
// Configure authentication
// The object below represents options for authentication
// The default options are good for now so we're not going to change anything
var authenticationOptions = new OAuthBearerAuthenticationOptions();
// Tell the app to use OAuthBearerAuthentication, passing in the authenticationOptions that we just instantiated
app.UseOAuthBearerAuthentication(authenticationOptions);
// Configure authorization
// We do want to customize is how authorization works in our system
// Same pattern as above, we're making options and then pass those options to the application
var authorizationOptions = new OAuthAuthorizationServerOptions
{
// We are going to configure 4 properties here to customize authorization
// We don't have https set up (secure set up)
// So just for testing purposes, we're going to allow insecure http
AllowInsecureHttp = true,
// Because we're not writing a controller that accepts information (that's taken care of by ASP.Net.Identity)
// We need to tell ASP.Net.Identity what route is; where is my user going to post to grab a token
// We're telling it the endpoint path is a new path string and you have to hit /api/token to grab a token
TokenEndpointPath = new PathString("/api/token"),
// The token is only good for 1 day
AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
// ASP.Net.Identity now wants to know where's the class that you wrote to intercept the events I'm going to throw at you
Provider = new PropertyManagerAuthorizationServerProvider()
};
app.UseOAuthAuthorizationServer(authorizationOptions);
}
开发者ID:IrisCaffin,项目名称:18-PropertyManager,代码行数:35,代码来源:Startup.cs
示例6: 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);
}
开发者ID:correobasura,项目名称:repositorioAngujarNet,代码行数:30,代码来源:Startup.cs
示例7: 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);
}
开发者ID:khoahoang,项目名称:MobileStoreAppHarbor,代码行数:25,代码来源:Startup.cs
示例8: ConfigureAuth
public void ConfigureAuth(IAppBuilder app)
{
var config = new HttpConfiguration();
// TODO: figure out how to get client certificates
// config.MessageHandlers.Add(new CertificateHandler());
config.MessageHandlers.Add(new ValidateRequestHandler());
OAuthBearerOptions = new OAuthAuthorizationServerOptions();
app.UseOAuthAuthorizationServer(OAuthBearerOptions);
OAuthBearerAuthenticationOptions = new OAuthBearerAuthenticationOptions();
app.UseOAuthBearerAuthentication(OAuthBearerAuthenticationOptions);
bool loadAssemblies = false;
if (bool.TryParse(ConfigurationManager.AppSettings["LoadAssemblyForTest"], out loadAssemblies))
{
config.Services.Replace(typeof(IAssembliesResolver), new AssemblyResolver());
}
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter("Bearer"));
app.UseWebApi(config);
}
开发者ID:divyang4481,项目名称:STS,代码行数:32,代码来源:OwinStartUp.cs
示例9: UseJwtBearerAuthentication
/// <summary>
/// Adds JWT bearer token middleware to your web application pipeline.
/// </summary>
/// <param name="app">The IAppBuilder passed to your configuration method.</param>
/// <param name="options">An options class that controls the middleware behavior.</param>
/// <returns>The original app parameter.</returns>
public static IAppBuilder UseJwtBearerAuthentication(this IAppBuilder app, JwtBearerAuthenticationOptions options)
{
if (app == null)
{
throw new ArgumentNullException("app");
}
if (options == null)
{
throw new ArgumentNullException("options");
}
var bearerOptions = new OAuthBearerAuthenticationOptions
{
Realm = options.Realm,
Provider = options.Provider,
AccessTokenFormat = new JwtFormat(options.AllowedAudiences, options.IssuerSecurityTokenProviders),
AuthenticationMode = options.AuthenticationMode,
AuthenticationType = options.AuthenticationType,
Description = options.Description
};
app.UseOAuthBearerAuthentication(bearerOptions);
return app;
}
开发者ID:ricardodemauro,项目名称:katana-clone,代码行数:31,代码来源:JwtBearerAuthenticationExtensions.cs
示例10: ConfigureAuth
// 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);
}
开发者ID:ShiftCtrlGroup,项目名称:socioboard-core,代码行数:27,代码来源:Startup.cs
示例11: 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);
}
开发者ID:kottt,项目名称:OAuthPrototype,代码行数:33,代码来源:Startup.cs
示例12: Configuration
public void Configuration(IAppBuilder app)
{
// token generation
var serverOptions = new OAuthAuthorizationServerOptions
{
// for demo purposes
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromHours(8),
Provider = new SimpleAuthorizationServerProvider(),
AuthenticationMode = AuthenticationMode.Active,
AuthenticationType = "Bearer"
};
#if Debug
System.Diagnostics.Debugger.Launch();
#endif
app.UseOAuthAuthorizationServer(serverOptions); // Adds OAuth2 Authorization Server capabilities to an OWIN web application.
/*
This middleware performs the request processing for the Authorize and Token endpoints defined by the OAuth2 specification.
See also http://tools.ietf.org/html/rfc6749
*/
// token consumption
var bearerOptions = new OAuthBearerAuthenticationOptions();
app.UseOAuthBearerAuthentication(bearerOptions); // Adds Bearer token processing to an OWIN application pipeline.
/*
This middleware understands appropriately formatted and
secured tokens which appear in the request header. If the Options.AuthenticationMode is Active, the claims within the
bearer token are added to the current request's IPrincipal User.
See also http://tools.ietf.org/html/rfc6749
*/
app.UseWebApi(WebApiConfig.Register()); // add WebAPI endpoint processing to OWIN pipeline
}
开发者ID:BenAtStatement1,项目名称:EmbeddedAuthorizationServer,代码行数:32,代码来源:Startup.cs
示例13: ConfigureOAuth
public void ConfigureOAuth(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Login"),
Provider = new CookieAuthenticationProvider()
{
OnApplyRedirect = ctx =>
{
if (!IsApiRequest(ctx.Request))
{
ctx.Response.Redirect(ctx.RedirectUri);
}
}
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
//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);
var OAuthBearerOptions = new OAuthBearerAuthenticationOptions();
// Token Generation
app.UseOAuthAuthorizationServer(NinjectResolver.CreateKernel.Value.Get<MyOAuthAuthorizationServerOptions>().GetOptions());
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions { Provider = new ApplicationOAuthBearerAuthenticationProvider()});
}
开发者ID:sirAspex,项目名称:InoDrive,代码行数:28,代码来源:AuthConfig.cs
示例14: 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);
}
开发者ID:danthomas,项目名称:AngularJSAuthentication,代码行数:33,代码来源:Startup.cs
示例15: 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);
}
开发者ID:joropeza,项目名称:AspNetAuth,代码行数:59,代码来源:Startup.cs
示例16: ConfigureAuth
public void ConfigureAuth(IAppBuilder app)
{
var options = new OAuthBearerAuthenticationOptions()
{
AccessTokenFormat = new TicketDataFormat()
};
app.UseOAuthBearerAuthentication(options);
}
开发者ID:pbarrios,项目名称:oauth-aspnet,代码行数:9,代码来源:Startup.Auth.cs
示例17: ConfigureAuth
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
// //use a cookie to temporarily store information about a user logging in with a third party login provider
// app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
OAuthBearerOptions = new OAuthBearerAuthenticationOptions();
// Token Generation
app.UseOAuthBearerTokens(OAuthServerOptions);
}
开发者ID:changLiuUNSW,项目名称:BDSystem,代码行数:10,代码来源:Startup.Auth.cs
示例18: ConfigureAuth
public static void ConfigureAuth(IAppBuilder app)
{
app.CreatePerOwinContext(ApplicationDbContext.Create);
OAuthBearerOptions = new OAuthBearerAuthenticationOptions();
//Token Consumption
app.UseOAuthBearerAuthentication(OAuthBearerOptions);
}
开发者ID:Yall1963,项目名称:resource-proxy,代码行数:9,代码来源:StartupOrt.cs
示例19: UseActiveDirectoryFederationServicesBearerAuthentication
/// <summary>
/// Adds Active Directory Federation Services (ADFS) issued JWT bearer token middleware to your web application pipeline.
/// </summary>
/// <param name="app">The IAppBuilder passed to your configuration method.</param>
/// <param name="options">An options class that controls the middleware behavior.</param>
/// <returns>The original app parameter.</returns>
public static IAppBuilder UseActiveDirectoryFederationServicesBearerAuthentication(this IAppBuilder app, ActiveDirectoryFederationServicesBearerAuthenticationOptions options)
{
if (options == null)
{
throw new ArgumentNullException("options");
}
var cachingSecurityTokenProvider = new WsFedCachingSecurityTokenProvider(options.MetadataEndpoint,
options.BackchannelCertificateValidator, options.BackchannelTimeout, options.BackchannelHttpHandler);
#pragma warning disable 618
JwtFormat jwtFormat = null;
if (options.TokenValidationParameters != null)
{
if (!string.IsNullOrWhiteSpace(options.Audience))
{
// Carry over obsolete property if set
if (string.IsNullOrWhiteSpace(options.TokenValidationParameters.ValidAudience))
{
options.TokenValidationParameters.ValidAudience = options.Audience;
}
else if (options.TokenValidationParameters.ValidAudiences == null)
{
options.TokenValidationParameters.ValidAudiences = new[] { options.Audience };
}
else
{
options.TokenValidationParameters.ValidAudiences = options.TokenValidationParameters.ValidAudiences.Concat(new[] { options.Audience });
}
}
jwtFormat = new JwtFormat(options.TokenValidationParameters, cachingSecurityTokenProvider);
}
else
{
jwtFormat = new JwtFormat(options.Audience, cachingSecurityTokenProvider);
}
#pragma warning restore 618
if (options.TokenHandler != null)
{
jwtFormat.TokenHandler = options.TokenHandler;
}
var bearerOptions = new OAuthBearerAuthenticationOptions
{
Realm = options.Realm,
Provider = options.Provider,
AccessTokenFormat = jwtFormat,
AuthenticationMode = options.AuthenticationMode,
AuthenticationType = options.AuthenticationType,
Description = options.Description
};
app.UseOAuthBearerAuthentication(bearerOptions);
return app;
}
开发者ID:Kstal,项目名称:Microsoft.Owin,代码行数:63,代码来源:ActiveDirectoryFederationServicesBearerAuthenticationExtensions.cs
示例20: Configuration
//public static OAuthAuthorizationServerOptions OAuthOptions { get; private set; }
//public static Func<UserManager<ApplicationUser>> UserManagerFactory { get; set; }
//public static string PublicClientId { get; private set; }
public void Configuration(IAppBuilder app)
{
//var idProvider = new CustomUserIdProvider();
//GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider), () => idProvider);
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
// PublicClientId = "self";
//OAuthOptions = new OAuthAuthorizationServerOptions
//{
// //TokenEndpointPath = new PathString("/Token"),
// Provider = new ApplicationOAuthProvider(PublicClientId),
// //AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
// AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
// #if DEBUG
// AllowInsecureHttp = true
// #endif
//};
OAuthBearerOptions = new OAuthBearerAuthenticationOptions()
{
//AccessTokenFormat = OAuthOptions.AccessTokenFormat,
//AccessTokenProvider = OAuthOptions.AccessTokenProvider,
//AuthenticationMode = OAuthOptions.AuthenticationMode,
//AuthenticationType = OAuthOptions.AuthenticationType,
//Description = OAuthOptions.Description,
Provider = new CustomBearerAuthenticationProvider(),
//SystemClock = OAuthOptions.SystemClock
};
OAuthBearerAuthenticationExtensions.UseOAuthBearerAuthentication(app, OAuthBearerOptions);
app.Map("/signalr", map =>
{
// Setup the CORS middleware to run before SignalR.
// By default this will allow all origins. You can
// configure the set of origins and/or http verbs by
// providing a cors options with a different policy.
map.UseCors(CorsOptions.AllowAll);
var hubConfiguration = new HubConfiguration
{
// You can enable JSONP by uncommenting line below.
// JSONP requests are insecure but some older browsers (and some
// versions of IE) require JSONP to work cross domain
// EnableJSONP = true
};
// Run the SignalR pipeline. We're not using MapSignalR
// since this branch already runs under the "/signalr"
// path.
map.RunSignalR(hubConfiguration);
});
//app.MapSignalR();
}
开发者ID:omeralper,项目名称:myApp,代码行数:58,代码来源:Startup.cs
注:本文中的Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationOptions类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论