Stardardizing middleware to use ConfigureOption lambda
This commit is contained in:
parent
84279c07cf
commit
5837ce160a
|
|
@ -72,26 +72,29 @@ namespace CookieSample
|
||||||
|
|
||||||
// You must first create an app with facebook and add it's ID and Secret to your config.json or user-secrets.
|
// You must first create an app with facebook and add it's ID and Secret to your config.json or user-secrets.
|
||||||
// https://developers.facebook.com/apps/
|
// https://developers.facebook.com/apps/
|
||||||
app.UseFacebookAuthentication(new FacebookOptions()
|
app.UseFacebookAuthentication(options =>
|
||||||
{
|
{
|
||||||
AppId = Configuration["facebook:appid"],
|
options.AppId = Configuration["facebook:appid"];
|
||||||
AppSecret = Configuration["facebook:appsecret"],
|
options.AppSecret = Configuration["facebook:appsecret"];
|
||||||
Scope = { "email" },
|
options.Scope.Add("email");
|
||||||
Fields = { "name", "email" },
|
options.Fields.Add("name");
|
||||||
|
options.Fields.Add("email");
|
||||||
});
|
});
|
||||||
|
|
||||||
// See config.json
|
// See config.json
|
||||||
app.UseOAuthAuthentication(new OAuthOptions
|
app.UseOAuthAuthentication(options =>
|
||||||
{
|
{
|
||||||
AuthenticationScheme = "Google-AccessToken",
|
options.AuthenticationScheme = "Google-AccessToken";
|
||||||
DisplayName = "Google-AccessToken",
|
options.DisplayName = "Google-AccessToken";
|
||||||
ClientId = Configuration["google:clientid"],
|
options.ClientId = Configuration["google:clientid"];
|
||||||
ClientSecret = Configuration["google:clientsecret"],
|
options.ClientSecret = Configuration["google:clientsecret"];
|
||||||
CallbackPath = new PathString("/signin-google-token"),
|
options.CallbackPath = new PathString("/signin-google-token");
|
||||||
AuthorizationEndpoint = GoogleDefaults.AuthorizationEndpoint,
|
options.AuthorizationEndpoint = GoogleDefaults.AuthorizationEndpoint;
|
||||||
TokenEndpoint = GoogleDefaults.TokenEndpoint,
|
options.TokenEndpoint = GoogleDefaults.TokenEndpoint;
|
||||||
Scope = { "openid", "profile", "email" },
|
options.Scope.Add("openid");
|
||||||
SaveTokensAsClaims = true
|
options.Scope.Add("profile");
|
||||||
|
options.Scope.Add("email");
|
||||||
|
options.SaveTokensAsClaims = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
// See config.json
|
// See config.json
|
||||||
|
|
@ -148,17 +151,17 @@ namespace CookieSample
|
||||||
The sample app can then be run via:
|
The sample app can then be run via:
|
||||||
dnx . web
|
dnx . web
|
||||||
*/
|
*/
|
||||||
app.UseOAuthAuthentication(new OAuthOptions
|
app.UseOAuthAuthentication(options =>
|
||||||
{
|
{
|
||||||
AuthenticationScheme = "Microsoft-AccessToken",
|
options.AuthenticationScheme = "Microsoft-AccessToken";
|
||||||
DisplayName = "MicrosoftAccount-AccessToken - Requires project changes",
|
options.DisplayName = "MicrosoftAccount-AccessToken - Requires project changes";
|
||||||
ClientId = Configuration["msa:clientid"],
|
options.ClientId = Configuration["msa:clientid"];
|
||||||
ClientSecret = Configuration["msa:clientsecret"],
|
options.ClientSecret = Configuration["msa:clientsecret"];
|
||||||
CallbackPath = new PathString("/signin-microsoft-token"),
|
options.CallbackPath = new PathString("/signin-microsoft-token");
|
||||||
AuthorizationEndpoint = MicrosoftAccountDefaults.AuthorizationEndpoint,
|
options.AuthorizationEndpoint = MicrosoftAccountDefaults.AuthorizationEndpoint;
|
||||||
TokenEndpoint = MicrosoftAccountDefaults.TokenEndpoint,
|
options.TokenEndpoint = MicrosoftAccountDefaults.TokenEndpoint;
|
||||||
Scope = { "wl.basic" },
|
options.Scope.Add("wl.basic");
|
||||||
SaveTokensAsClaims = true
|
options.SaveTokensAsClaims = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
//// You must first create an app with live.com and add it's ID and Secret to your config.json or user-secrets.
|
//// You must first create an app with live.com and add it's ID and Secret to your config.json or user-secrets.
|
||||||
|
|
@ -172,32 +175,32 @@ namespace CookieSample
|
||||||
|
|
||||||
// See config.json
|
// See config.json
|
||||||
// https://github.com/settings/applications/
|
// https://github.com/settings/applications/
|
||||||
app.UseOAuthAuthentication(new OAuthOptions
|
app.UseOAuthAuthentication(options =>
|
||||||
{
|
{
|
||||||
AuthenticationScheme = "GitHub-AccessToken",
|
options.AuthenticationScheme = "GitHub-AccessToken";
|
||||||
DisplayName = "Github-AccessToken",
|
options.DisplayName = "Github-AccessToken";
|
||||||
ClientId = Configuration["github-token:clientid"],
|
options.ClientId = Configuration["github-token:clientid"];
|
||||||
ClientSecret = Configuration["github-token:clientsecret"],
|
options.ClientSecret = Configuration["github-token:clientsecret"];
|
||||||
CallbackPath = new PathString("/signin-github-token"),
|
options.CallbackPath = new PathString("/signin-github-token");
|
||||||
AuthorizationEndpoint = "https://github.com/login/oauth/authorize",
|
options.AuthorizationEndpoint = "https://github.com/login/oauth/authorize";
|
||||||
TokenEndpoint = "https://github.com/login/oauth/access_token",
|
options.TokenEndpoint = "https://github.com/login/oauth/access_token";
|
||||||
SaveTokensAsClaims = true
|
options.SaveTokensAsClaims = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
// See config.json
|
// See config.json
|
||||||
app.UseOAuthAuthentication(new OAuthOptions
|
app.UseOAuthAuthentication(options =>
|
||||||
{
|
{
|
||||||
AuthenticationScheme = "GitHub",
|
options.AuthenticationScheme = "GitHub";
|
||||||
DisplayName = "Github",
|
options.DisplayName = "Github";
|
||||||
ClientId = Configuration["github:clientid"],
|
options.ClientId = Configuration["github:clientid"];
|
||||||
ClientSecret = Configuration["github:clientsecret"],
|
options.ClientSecret = Configuration["github:clientsecret"];
|
||||||
CallbackPath = new PathString("/signin-github"),
|
options.CallbackPath = new PathString("/signin-github");
|
||||||
AuthorizationEndpoint = "https://github.com/login/oauth/authorize",
|
options.AuthorizationEndpoint = "https://github.com/login/oauth/authorize";
|
||||||
TokenEndpoint = "https://github.com/login/oauth/access_token",
|
options.TokenEndpoint = "https://github.com/login/oauth/access_token";
|
||||||
UserInformationEndpoint = "https://api.github.com/user",
|
options.UserInformationEndpoint = "https://api.github.com/user";
|
||||||
ClaimsIssuer = "OAuth2-Github",
|
options.ClaimsIssuer = "OAuth2-Github";
|
||||||
// Retrieving user information is unique to each provider.
|
// Retrieving user information is unique to each provider.
|
||||||
Events = new OAuthEvents
|
options.Events = new OAuthEvents
|
||||||
{
|
{
|
||||||
OnCreatingTicket = async context =>
|
OnCreatingTicket = async context =>
|
||||||
{
|
{
|
||||||
|
|
@ -210,7 +213,7 @@ namespace CookieSample
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
var user = JObject.Parse(await response.Content.ReadAsStringAsync());
|
var user = JObject.Parse(await response.Content.ReadAsStringAsync());
|
||||||
|
|
||||||
var identifier = user.Value<string>("id");
|
var identifier = user.Value<string>("id");
|
||||||
if (!string.IsNullOrEmpty(identifier))
|
if (!string.IsNullOrEmpty(identifier))
|
||||||
{
|
{
|
||||||
|
|
@ -243,7 +246,7 @@ namespace CookieSample
|
||||||
ClaimValueTypes.String, context.Options.ClaimsIssuer));
|
ClaimValueTypes.String, context.Options.ClaimsIssuer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// Choose an authentication type
|
// Choose an authentication type
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Builder
|
||||||
throw new ArgumentNullException(nameof(app));
|
throw new ArgumentNullException(nameof(app));
|
||||||
}
|
}
|
||||||
|
|
||||||
return app.UseCookieAuthentication(new CookieAuthenticationOptions());
|
return app.UseCookieAuthentication(options => { });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -38,32 +38,13 @@ namespace Microsoft.AspNet.Builder
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(app));
|
throw new ArgumentNullException(nameof(app));
|
||||||
}
|
}
|
||||||
|
if (configureOptions == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(configureOptions));
|
||||||
|
}
|
||||||
|
|
||||||
var options = new CookieAuthenticationOptions();
|
var options = new CookieAuthenticationOptions();
|
||||||
if (configureOptions != null)
|
configureOptions(options);
|
||||||
{
|
|
||||||
configureOptions(options);
|
|
||||||
}
|
|
||||||
return app.UseCookieAuthentication(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds the <see cref="CookieAuthenticationMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables cookie authentication capabilities.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
|
|
||||||
/// <param name="options">A <see cref="JwtBearerOptions"/> that specifies options for the middleware.</param>
|
|
||||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
|
||||||
public static IApplicationBuilder UseCookieAuthentication(this IApplicationBuilder app, CookieAuthenticationOptions options)
|
|
||||||
{
|
|
||||||
if (app == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(app));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
return app.UseMiddleware<CookieAuthenticationMiddleware>(options);
|
return app.UseMiddleware<CookieAuthenticationMiddleware>(options);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,27 +11,6 @@ namespace Microsoft.AspNet.Builder
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class FacebookAppBuilderExtensions
|
public static class FacebookAppBuilderExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Adds the <see cref="FacebookMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables Facebook authentication capabilities.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
|
|
||||||
/// <param name="options">A <see cref="FacebookOptions"/> that specifies options for the middleware.</param>
|
|
||||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
|
||||||
public static IApplicationBuilder UseFacebookAuthentication(this IApplicationBuilder app, FacebookOptions options)
|
|
||||||
{
|
|
||||||
if (app == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(app));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
return app.UseMiddleware<FacebookMiddleware>(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the <see cref="FacebookMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables Facebook authentication capabilities.
|
/// Adds the <see cref="FacebookMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables Facebook authentication capabilities.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -44,13 +23,15 @@ namespace Microsoft.AspNet.Builder
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(app));
|
throw new ArgumentNullException(nameof(app));
|
||||||
}
|
}
|
||||||
|
if (configureOptions == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(configureOptions));
|
||||||
|
}
|
||||||
|
|
||||||
var options = new FacebookOptions();
|
var options = new FacebookOptions();
|
||||||
if (configureOptions != null)
|
configureOptions(options);
|
||||||
{
|
|
||||||
configureOptions(options);
|
return app.UseMiddleware<FacebookMiddleware>(options);
|
||||||
}
|
|
||||||
return app.UseFacebookAuthentication(options);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,27 +11,6 @@ namespace Microsoft.AspNet.Builder
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class GoogleAppBuilderExtensions
|
public static class GoogleAppBuilderExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Adds the <see cref="GoogleMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables Google authentication capabilities.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
|
|
||||||
/// <param name="options">A <see cref="GoogleOptions"/> that specifies options for the middleware.</param>
|
|
||||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
|
||||||
public static IApplicationBuilder UseGoogleAuthentication(this IApplicationBuilder app, GoogleOptions options)
|
|
||||||
{
|
|
||||||
if (app == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(app));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
return app.UseMiddleware<GoogleMiddleware>(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the <see cref="GoogleMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables Google authentication capabilities.
|
/// Adds the <see cref="GoogleMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables Google authentication capabilities.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -44,13 +23,15 @@ namespace Microsoft.AspNet.Builder
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(app));
|
throw new ArgumentNullException(nameof(app));
|
||||||
}
|
}
|
||||||
|
if (configureOptions == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(configureOptions));
|
||||||
|
}
|
||||||
|
|
||||||
var options = new GoogleOptions();
|
var options = new GoogleOptions();
|
||||||
if (configureOptions != null)
|
configureOptions(options);
|
||||||
{
|
|
||||||
configureOptions(options);
|
return app.UseMiddleware<GoogleMiddleware>(options);
|
||||||
}
|
|
||||||
return app.UseGoogleAuthentication(options);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,33 +11,6 @@ namespace Microsoft.AspNet.Builder
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class JwtBearerAppBuilderExtensions
|
public static class JwtBearerAppBuilderExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Adds the <see cref="JwtBearerMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables Bearer token processing capabilities.
|
|
||||||
/// 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. If the Options.AuthenticationMode
|
|
||||||
/// is Passive, then the current request is not modified, but IAuthenticationManager AuthenticateAsync may be used at
|
|
||||||
/// any time to obtain the claims from the request's bearer token.
|
|
||||||
/// See also http://tools.ietf.org/html/rfc6749
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
|
|
||||||
/// <param name="options">A <see cref="JwtBearerOptions"/> that specifies options for the middleware.</param>
|
|
||||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
|
||||||
public static IApplicationBuilder UseJwtBearerAuthentication(this IApplicationBuilder app, JwtBearerOptions options)
|
|
||||||
{
|
|
||||||
if (app == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(app));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
return app.UseMiddleware<JwtBearerMiddleware>(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the <see cref="JwtBearerMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables Bearer token processing capabilities.
|
/// Adds the <see cref="JwtBearerMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables Bearer token processing capabilities.
|
||||||
/// This middleware understands appropriately
|
/// This middleware understands appropriately
|
||||||
|
|
@ -56,13 +29,15 @@ namespace Microsoft.AspNet.Builder
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(app));
|
throw new ArgumentNullException(nameof(app));
|
||||||
}
|
}
|
||||||
|
if (configureOptions == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(configureOptions));
|
||||||
|
}
|
||||||
|
|
||||||
var options = new JwtBearerOptions();
|
var options = new JwtBearerOptions();
|
||||||
if (configureOptions != null)
|
configureOptions(options);
|
||||||
{
|
|
||||||
configureOptions(options);
|
return app.UseMiddleware<JwtBearerMiddleware>(options);
|
||||||
}
|
|
||||||
return app.UseJwtBearerAuthentication(options);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,27 +11,6 @@ namespace Microsoft.AspNet.Builder
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class MicrosoftAccountAppBuilderExtensions
|
public static class MicrosoftAccountAppBuilderExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Adds the <see cref="MicrosoftAccountMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables Microsoft Account authentication capabilities.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
|
|
||||||
/// <param name="options">A <see cref="MicrosoftAccountOptions"/> that specifies options for the middleware.</param>
|
|
||||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
|
||||||
public static IApplicationBuilder UseMicrosoftAccountAuthentication(this IApplicationBuilder app, MicrosoftAccountOptions options)
|
|
||||||
{
|
|
||||||
if (app == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(app));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
return app.UseMiddleware<MicrosoftAccountMiddleware>(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the <see cref="MicrosoftAccountMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables Microsoft Account authentication capabilities.
|
/// Adds the <see cref="MicrosoftAccountMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables Microsoft Account authentication capabilities.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -44,13 +23,15 @@ namespace Microsoft.AspNet.Builder
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(app));
|
throw new ArgumentNullException(nameof(app));
|
||||||
}
|
}
|
||||||
|
if (configureOptions == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(configureOptions));
|
||||||
|
}
|
||||||
|
|
||||||
var options = new MicrosoftAccountOptions();
|
var options = new MicrosoftAccountOptions();
|
||||||
if (configureOptions != null)
|
configureOptions(options);
|
||||||
{
|
|
||||||
configureOptions(options);
|
return app.UseMiddleware<MicrosoftAccountMiddleware>(options);
|
||||||
}
|
|
||||||
return app.UseMicrosoftAccountAuthentication(options);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,37 +23,13 @@ namespace Microsoft.AspNet.Builder
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(app));
|
throw new ArgumentNullException(nameof(app));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configureOptions == null)
|
if (configureOptions == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(configureOptions));
|
throw new ArgumentNullException(nameof(configureOptions));
|
||||||
}
|
}
|
||||||
|
|
||||||
var options = new OAuthOptions();
|
var options = new OAuthOptions();
|
||||||
if (configureOptions != null)
|
configureOptions(options);
|
||||||
{
|
|
||||||
configureOptions(options);
|
|
||||||
}
|
|
||||||
return app.UseOAuthAuthentication(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds the <see cref="OAuthMiddleware{TOptions}"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables OAuth 2.0 authentication capabilities.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
|
|
||||||
/// <param name="options">A <see cref="OAuthOptions"/> that specifies options for the middleware.</param>
|
|
||||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
|
||||||
public static IApplicationBuilder UseOAuthAuthentication(this IApplicationBuilder app, OAuthOptions options)
|
|
||||||
{
|
|
||||||
if (app == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(app));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
return app.UseMiddleware<OAuthMiddleware<OAuthOptions>>(options);
|
return app.UseMiddleware<OAuthMiddleware<OAuthOptions>>(options);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,7 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Http;
|
|
||||||
using Microsoft.AspNet.Http;
|
|
||||||
using Microsoft.AspNet.Http.Authentication;
|
using Microsoft.AspNet.Http.Authentication;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Authentication.OAuth
|
namespace Microsoft.AspNet.Authentication.OAuth
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ namespace Microsoft.AspNet.Builder
|
||||||
/// Adds the <see cref="OpenIdConnectMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables OpenID Connect authentication capabilities.
|
/// Adds the <see cref="OpenIdConnectMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables OpenID Connect authentication capabilities.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
|
/// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
|
||||||
/// <param name="options">An action delegate to configure the provided <see cref="OpenIdConnectOptions"/>.</param>
|
/// <param name="configureOptions">An action delegate to configure the provided <see cref="OpenIdConnectOptions"/>.</param>
|
||||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||||
public static IApplicationBuilder UseOpenIdConnectAuthentication(this IApplicationBuilder app, Action<OpenIdConnectOptions> configureOptions)
|
public static IApplicationBuilder UseOpenIdConnectAuthentication(this IApplicationBuilder app, Action<OpenIdConnectOptions> configureOptions)
|
||||||
{
|
{
|
||||||
|
|
@ -23,33 +23,13 @@ namespace Microsoft.AspNet.Builder
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(app));
|
throw new ArgumentNullException(nameof(app));
|
||||||
}
|
}
|
||||||
|
if (configureOptions == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(configureOptions));
|
||||||
|
}
|
||||||
|
|
||||||
var options = new OpenIdConnectOptions();
|
var options = new OpenIdConnectOptions();
|
||||||
if (configureOptions != null)
|
configureOptions(options);
|
||||||
{
|
|
||||||
configureOptions(options);
|
|
||||||
}
|
|
||||||
return app.UseOpenIdConnectAuthentication(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds the <see cref="OpenIdConnectMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables OpenID Connect authentication capabilities.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
|
|
||||||
/// <param name="options">An <see cref="OpenIdConnectOptions"/> that specifies options for the middleware.</param>
|
|
||||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
|
||||||
public static IApplicationBuilder UseOpenIdConnectAuthentication(this IApplicationBuilder app, OpenIdConnectOptions options)
|
|
||||||
{
|
|
||||||
if (app == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(app));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
return app.UseMiddleware<OpenIdConnectMiddleware>(options);
|
return app.UseMiddleware<OpenIdConnectMiddleware>(options);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,32 +23,13 @@ namespace Microsoft.AspNet.Builder
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(app));
|
throw new ArgumentNullException(nameof(app));
|
||||||
}
|
}
|
||||||
|
if (configureOptions == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(configureOptions));
|
||||||
|
}
|
||||||
|
|
||||||
var options = new TwitterOptions();
|
var options = new TwitterOptions();
|
||||||
if (configureOptions != null)
|
configureOptions(options);
|
||||||
{
|
|
||||||
configureOptions(options);
|
|
||||||
}
|
|
||||||
return app.UseTwitterAuthentication(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds the <see cref="TwitterMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables Twitter authentication capabilities.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
|
|
||||||
/// <param name="options">A <see cref="TwitterOptions"/> that specifies options for the middleware.</param>
|
|
||||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
|
||||||
public static IApplicationBuilder UseTwitterAuthentication(this IApplicationBuilder app, TwitterOptions options)
|
|
||||||
{
|
|
||||||
if (app == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(app));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
return app.UseMiddleware<TwitterMiddleware>(options);
|
return app.UseMiddleware<TwitterMiddleware>(options);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,17 +13,6 @@ namespace Microsoft.AspNet.Builder
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ClaimsTransformationAppBuilderExtensions
|
public static class ClaimsTransformationAppBuilderExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Adds the <see cref="ClaimsTransformationMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables claims transformation capabilities.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
|
|
||||||
/// <param name="options">A <see cref="ClaimsTransformationOptions"/> that specifies options for the middleware.</param>
|
|
||||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
|
||||||
public static IApplicationBuilder UseClaimsTransformation(this IApplicationBuilder app, ClaimsTransformationOptions options)
|
|
||||||
{
|
|
||||||
return app.UseMiddleware<ClaimsTransformationMiddleware>(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the <see cref="ClaimsTransformationMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables claims transformation capabilities.
|
/// Adds the <see cref="ClaimsTransformationMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables claims transformation capabilities.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -32,12 +21,19 @@ namespace Microsoft.AspNet.Builder
|
||||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||||
public static IApplicationBuilder UseClaimsTransformation(this IApplicationBuilder app, Func<ClaimsPrincipal, Task<ClaimsPrincipal>> transform)
|
public static IApplicationBuilder UseClaimsTransformation(this IApplicationBuilder app, Func<ClaimsPrincipal, Task<ClaimsPrincipal>> transform)
|
||||||
{
|
{
|
||||||
var options = new ClaimsTransformationOptions();
|
if (app == null)
|
||||||
options.Transformer = new ClaimsTransformer
|
|
||||||
{
|
{
|
||||||
OnTransform = transform
|
throw new ArgumentNullException(nameof(app));
|
||||||
};
|
}
|
||||||
return app.UseClaimsTransformation(options);
|
if (transform == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(transform));
|
||||||
|
}
|
||||||
|
|
||||||
|
return app.UseClaimsTransformation(options =>
|
||||||
|
{
|
||||||
|
options.Transformer = new ClaimsTransformer { OnTransform = transform };
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -48,12 +44,19 @@ namespace Microsoft.AspNet.Builder
|
||||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||||
public static IApplicationBuilder UseClaimsTransformation(this IApplicationBuilder app, Action<ClaimsTransformationOptions> configureOptions)
|
public static IApplicationBuilder UseClaimsTransformation(this IApplicationBuilder app, Action<ClaimsTransformationOptions> configureOptions)
|
||||||
{
|
{
|
||||||
var options = new ClaimsTransformationOptions();
|
if (app == null)
|
||||||
if (configureOptions != null)
|
|
||||||
{
|
{
|
||||||
configureOptions(options);
|
throw new ArgumentNullException(nameof(app));
|
||||||
}
|
}
|
||||||
return app.UseClaimsTransformation(options);
|
if (configureOptions == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(configureOptions));
|
||||||
|
}
|
||||||
|
|
||||||
|
var options = new ClaimsTransformationOptions();
|
||||||
|
configureOptions(options);
|
||||||
|
|
||||||
|
return app.UseMiddleware<ClaimsTransformationMiddleware>(options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,17 +11,6 @@ namespace Microsoft.AspNet.Builder
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class CookiePolicyAppBuilderExtensions
|
public static class CookiePolicyAppBuilderExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Adds the <see cref="CookiePolicyMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables cookie policy capabilities.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
|
|
||||||
/// <param name="options">A <see cref="CookiePolicyOptions"/> that specifies options for the middleware.</param>
|
|
||||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
|
||||||
public static IApplicationBuilder UseCookiePolicy(this IApplicationBuilder app, CookiePolicyOptions options)
|
|
||||||
{
|
|
||||||
return app.UseMiddleware<CookiePolicyMiddleware>(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the <see cref="CookiePolicyMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables cookie policy capabilities.
|
/// Adds the <see cref="CookiePolicyMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>, which enables cookie policy capabilities.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -30,12 +19,19 @@ namespace Microsoft.AspNet.Builder
|
||||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||||
public static IApplicationBuilder UseCookiePolicy(this IApplicationBuilder app, Action<CookiePolicyOptions> configureOptions)
|
public static IApplicationBuilder UseCookiePolicy(this IApplicationBuilder app, Action<CookiePolicyOptions> configureOptions)
|
||||||
{
|
{
|
||||||
var options = new CookiePolicyOptions();
|
if (app == null)
|
||||||
if (configureOptions != null)
|
|
||||||
{
|
{
|
||||||
configureOptions(options);
|
throw new ArgumentNullException(nameof(app));
|
||||||
}
|
}
|
||||||
return app.UseCookiePolicy(options);
|
if (configureOptions == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(configureOptions));
|
||||||
|
}
|
||||||
|
|
||||||
|
var options = new CookiePolicyOptions();
|
||||||
|
configureOptions(options);
|
||||||
|
|
||||||
|
return app.UseMiddleware<CookiePolicyMiddleware>(options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -793,7 +793,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
.Configure(app =>
|
.Configure(app =>
|
||||||
{
|
{
|
||||||
app.UseCookieAuthentication(options => options.CookieName = "One");
|
app.UseCookieAuthentication(options => options.CookieName = "One");
|
||||||
app.UseCookieAuthentication(new CookieAuthenticationOptions());
|
app.UseCookieAuthentication();
|
||||||
app.Run(context => context.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(new ClaimsIdentity())));
|
app.Run(context => context.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(new ClaimsIdentity())));
|
||||||
})
|
})
|
||||||
.ConfigureServices(services => services.AddAuthentication());
|
.ConfigureServices(services => services.AddAuthentication());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue