React to auth feature API changes.

This commit is contained in:
Chris Ross 2015-04-24 09:39:17 -07:00
parent 87c31c5526
commit 63fc18b945
21 changed files with 88 additions and 130 deletions

View File

@ -28,7 +28,7 @@ namespace CookieSample
if (string.IsNullOrEmpty(context.User.Identity.Name)) if (string.IsNullOrEmpty(context.User.Identity.Name))
{ {
var user = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "bob") })); var user = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "bob") }));
context.Response.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, user); context.Authentication.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, user);
context.Response.ContentType = "text/plain"; context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("Hello First timer"); await context.Response.WriteAsync("Hello First timer");
return; return;

View File

@ -36,7 +36,7 @@ namespace CookieSessionSample
{ {
claims.Add(new Claim(ClaimTypes.Role, "SomeRandomGroup" + i, ClaimValueTypes.String, "IssuedByBob", "OriginalIssuerJoe")); claims.Add(new Claim(ClaimTypes.Role, "SomeRandomGroup" + i, ClaimValueTypes.String, "IssuedByBob", "OriginalIssuerJoe"));
} }
context.Response.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(new ClaimsIdentity(claims))); context.Authentication.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(new ClaimsIdentity(claims)));
context.Response.ContentType = "text/plain"; context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("Hello First timer"); await context.Response.WriteAsync("Hello First timer");
return; return;

View File

@ -40,7 +40,7 @@ namespace OpenIdConnectSample
{ {
if (string.IsNullOrEmpty(context.User.Identity.Name)) if (string.IsNullOrEmpty(context.User.Identity.Name))
{ {
context.Response.Challenge(new AuthenticationProperties { RedirectUri = "/" }, OpenIdConnectAuthenticationDefaults.AuthenticationScheme); context.Authentication.Challenge(OpenIdConnectAuthenticationDefaults.AuthenticationScheme, new AuthenticationProperties { RedirectUri = "/" });
context.Response.ContentType = "text/plain"; context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("Hello First timer"); await context.Response.WriteAsync("Hello First timer");

View File

@ -188,14 +188,14 @@ namespace CookieSample
{ {
// By default the client will be redirect back to the URL that issued the challenge (/login?authtype=foo), // By default the client will be redirect back to the URL that issued the challenge (/login?authtype=foo),
// send them to the home page instead (/). // send them to the home page instead (/).
context.Response.Challenge(new AuthenticationProperties() { RedirectUri = "/" }, authType); context.Authentication.Challenge(authType, new AuthenticationProperties() { RedirectUri = "/" });
return; return;
} }
context.Response.ContentType = "text/html"; context.Response.ContentType = "text/html";
await context.Response.WriteAsync("<html><body>"); await context.Response.WriteAsync("<html><body>");
await context.Response.WriteAsync("Choose an authentication scheme: <br>"); await context.Response.WriteAsync("Choose an authentication scheme: <br>");
foreach (var type in context.GetAuthenticationSchemes()) foreach (var type in context.Authentication.GetAuthenticationSchemes())
{ {
await context.Response.WriteAsync("<a href=\"?authscheme=" + type.AuthenticationScheme + "\">" + (type.Caption ?? "(suppressed)") + "</a><br>"); await context.Response.WriteAsync("<a href=\"?authscheme=" + type.AuthenticationScheme + "\">" + (type.Caption ?? "(suppressed)") + "</a><br>");
} }
@ -208,7 +208,7 @@ namespace CookieSample
{ {
signoutApp.Run(async context => signoutApp.Run(async context =>
{ {
context.Response.SignOut(CookieAuthenticationDefaults.AuthenticationScheme); context.Authentication.SignOut(CookieAuthenticationDefaults.AuthenticationScheme);
context.Response.ContentType = "text/html"; context.Response.ContentType = "text/html";
await context.Response.WriteAsync("<html><body>"); await context.Response.WriteAsync("<html><body>");
await context.Response.WriteAsync("You have been logged out. Goodbye " + context.User.Identity.Name + "<br>"); await context.Response.WriteAsync("You have been logged out. Goodbye " + context.User.Identity.Name + "<br>");
@ -223,7 +223,7 @@ namespace CookieSample
if (string.IsNullOrEmpty(context.User.Identity.Name)) if (string.IsNullOrEmpty(context.User.Identity.Name))
{ {
// The cookie middleware will intercept this 401 and redirect to /login // The cookie middleware will intercept this 401 and redirect to /login
context.Response.Challenge(); context.Authentication.Challenge();
return; return;
} }
await next(); await next();

View File

@ -157,23 +157,23 @@ namespace Microsoft.AspNet.Authentication.Cookies
Options, Options,
Options.AuthenticationScheme, Options.AuthenticationScheme,
signin.Principal, signin.Principal,
signin.Properties, new AuthenticationProperties(signin.Properties),
cookieOptions); cookieOptions);
DateTimeOffset issuedUtc; DateTimeOffset issuedUtc;
if (signin.Properties.IssuedUtc.HasValue) if (signInContext.Properties.IssuedUtc.HasValue)
{ {
issuedUtc = signin.Properties.IssuedUtc.Value; issuedUtc = signInContext.Properties.IssuedUtc.Value;
} }
else else
{ {
issuedUtc = Options.SystemClock.UtcNow; issuedUtc = Options.SystemClock.UtcNow;
signin.Properties.IssuedUtc = issuedUtc; signInContext.Properties.IssuedUtc = issuedUtc;
} }
if (!signin.Properties.ExpiresUtc.HasValue) if (!signInContext.Properties.ExpiresUtc.HasValue)
{ {
signin.Properties.ExpiresUtc = issuedUtc.Add(Options.ExpireTimeSpan); signInContext.Properties.ExpiresUtc = issuedUtc.Add(Options.ExpireTimeSpan);
} }
Options.Notifications.ResponseSignIn(signInContext); Options.Notifications.ResponseSignIn(signInContext);
@ -226,7 +226,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
Context, Context,
Options, Options,
cookieOptions); cookieOptions);
Options.Notifications.ResponseSignOut(context); Options.Notifications.ResponseSignOut(context);
Options.CookieManager.DeleteCookie( Options.CookieManager.DeleteCookie(

View File

@ -102,14 +102,14 @@ namespace Microsoft.AspNet.Authentication.Google
string name, string defaultValue = null) string name, string defaultValue = null)
{ {
string value; string value;
if (!properties.Dictionary.TryGetValue(name, out value)) if (!properties.Items.TryGetValue(name, out value))
{ {
value = defaultValue; value = defaultValue;
} }
else else
{ {
// Remove the parameter from AuthenticationProperties so it won't be serialized to state parameter // Remove the parameter from AuthenticationProperties so it won't be serialized to state parameter
properties.Dictionary.Remove(name); properties.Items.Remove(name);
} }
if (value == null) if (value == null)

View File

@ -56,7 +56,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
if (context.SignInScheme != null && context.Principal != null) if (context.SignInScheme != null && context.Principal != null)
{ {
Context.Response.SignIn(context.SignInScheme, context.Principal, context.Properties); Context.Authentication.SignIn(context.SignInScheme, context.Principal, context.Properties);
} }
if (!context.IsRequestCompleted && context.RedirectUri != null) if (!context.IsRequestCompleted && context.RedirectUri != null)

View File

@ -161,7 +161,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
// When redeeming a 'code' for an AccessToken, this value is needed // When redeeming a 'code' for an AccessToken, this value is needed
if (!string.IsNullOrWhiteSpace(Options.RedirectUri)) if (!string.IsNullOrWhiteSpace(Options.RedirectUri))
{ {
properties.Dictionary.Add(OpenIdConnectAuthenticationDefaults.RedirectUriUsedForCodeKey, Options.RedirectUri); properties.Items.Add(OpenIdConnectAuthenticationDefaults.RedirectUriUsedForCodeKey, Options.RedirectUri);
} }
if (_configuration == null && Options.ConfigurationManager != null) if (_configuration == null && Options.ConfigurationManager != null)
@ -385,12 +385,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
ticket = new AuthenticationTicket(principal, properties, Options.AuthenticationScheme); ticket = new AuthenticationTicket(principal, properties, Options.AuthenticationScheme);
if (!string.IsNullOrWhiteSpace(message.SessionState)) if (!string.IsNullOrWhiteSpace(message.SessionState))
{ {
ticket.Properties.Dictionary[OpenIdConnectSessionProperties.SessionState] = message.SessionState; ticket.Properties.Items[OpenIdConnectSessionProperties.SessionState] = message.SessionState;
} }
if (_configuration != null && !string.IsNullOrWhiteSpace(_configuration.CheckSessionIframe)) if (_configuration != null && !string.IsNullOrWhiteSpace(_configuration.CheckSessionIframe))
{ {
ticket.Properties.Dictionary[OpenIdConnectSessionProperties.CheckSessionIFrame] = _configuration.CheckSessionIframe; ticket.Properties.Items[OpenIdConnectSessionProperties.CheckSessionIFrame] = _configuration.CheckSessionIframe;
} }
// Rename? // Rename?
@ -466,8 +466,8 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
Code = message.Code, Code = message.Code,
JwtSecurityToken = jwt, JwtSecurityToken = jwt,
ProtocolMessage = message, ProtocolMessage = message,
RedirectUri = ticket.Properties.Dictionary.ContainsKey(OpenIdConnectAuthenticationDefaults.RedirectUriUsedForCodeKey) ? RedirectUri = ticket.Properties.Items.ContainsKey(OpenIdConnectAuthenticationDefaults.RedirectUriUsedForCodeKey) ?
ticket.Properties.Dictionary[OpenIdConnectAuthenticationDefaults.RedirectUriUsedForCodeKey] : string.Empty, ticket.Properties.Items[OpenIdConnectAuthenticationDefaults.RedirectUriUsedForCodeKey] : string.Empty,
}; };
await Options.Notifications.AuthorizationCodeReceived(authorizationCodeReceivedNotification); await Options.Notifications.AuthorizationCodeReceived(authorizationCodeReceivedNotification);
@ -632,7 +632,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
{ {
if (ticket.Principal != null) if (ticket.Principal != null)
{ {
Request.HttpContext.Response.SignIn(Options.SignInScheme, ticket.Principal, ticket.Properties); Request.HttpContext.Authentication.SignIn(Options.SignInScheme, ticket.Principal, ticket.Properties);
} }
// Redirect back to the original secured resource, if any. // Redirect back to the original secured resource, if any.

View File

@ -208,7 +208,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
if (context.SignInScheme != null && context.Principal != null) if (context.SignInScheme != null && context.Principal != null)
{ {
Context.Response.SignIn(context.SignInScheme, context.Principal, context.Properties); Context.Authentication.SignIn(context.SignInScheme, context.Principal, context.Properties);
} }
if (!context.IsRequestCompleted && context.RedirectUri != null) if (!context.IsRequestCompleted && context.RedirectUri != null)

View File

@ -31,9 +31,9 @@ namespace Microsoft.AspNet.Authentication
private AuthenticationOptions _baseOptions; private AuthenticationOptions _baseOptions;
protected IChallengeContext ChallengeContext { get; set; } protected ChallengeContext ChallengeContext { get; set; }
protected SignInContext SignInContext { get; set; } protected SignInContext SignInContext { get; set; }
protected ISignOutContext SignOutContext { get; set; } protected SignOutContext SignOutContext { get; set; }
protected HttpContext Context { get; private set; } protected HttpContext Context { get; private set; }
@ -145,9 +145,9 @@ namespace Microsoft.AspNet.Authentication
return Task.FromResult(false); return Task.FromResult(false);
} }
public virtual void GetDescriptions(IDescribeSchemesContext describeContext) public virtual void GetDescriptions(DescribeSchemesContext describeContext)
{ {
describeContext.Accept(BaseOptions.Description.Dictionary); describeContext.Accept(BaseOptions.Description.Items);
if (PriorHandler != null) if (PriorHandler != null)
{ {
@ -155,7 +155,7 @@ namespace Microsoft.AspNet.Authentication
} }
} }
public virtual void Authenticate(IAuthenticateContext context) public virtual void Authenticate(AuthenticateContext context)
{ {
if (ShouldHandleScheme(context.AuthenticationScheme)) if (ShouldHandleScheme(context.AuthenticationScheme))
{ {
@ -163,7 +163,7 @@ namespace Microsoft.AspNet.Authentication
if (ticket?.Principal != null) if (ticket?.Principal != null)
{ {
AuthenticateCalled = true; AuthenticateCalled = true;
context.Authenticated(ticket.Principal, ticket.Properties.Dictionary, BaseOptions.Description.Dictionary); context.Authenticated(ticket.Principal, ticket.Properties.Items, BaseOptions.Description.Items);
} }
else else
{ {
@ -177,7 +177,7 @@ namespace Microsoft.AspNet.Authentication
} }
} }
public virtual async Task AuthenticateAsync(IAuthenticateContext context) public virtual async Task AuthenticateAsync(AuthenticateContext context)
{ {
if (ShouldHandleScheme(context.AuthenticationScheme)) if (ShouldHandleScheme(context.AuthenticationScheme))
{ {
@ -185,7 +185,7 @@ namespace Microsoft.AspNet.Authentication
if (ticket?.Principal != null) if (ticket?.Principal != null)
{ {
AuthenticateCalled = true; AuthenticateCalled = true;
context.Authenticated(ticket.Principal, ticket.Properties.Dictionary, BaseOptions.Description.Dictionary); context.Authenticated(ticket.Principal, ticket.Properties.Items, BaseOptions.Description.Items);
} }
else else
{ {
@ -326,13 +326,13 @@ namespace Microsoft.AspNet.Authentication
return Task.FromResult(0); return Task.FromResult(0);
} }
public virtual void SignIn(ISignInContext context) public virtual void SignIn(SignInContext context)
{ {
if (ShouldHandleScheme(context.AuthenticationScheme)) if (ShouldHandleScheme(context.AuthenticationScheme))
{ {
SignInContext = new SignInContext(context.Principal, new AuthenticationProperties(context.Properties)); SignInContext = context;
SignOutContext = null; SignOutContext = null;
context.Accept(BaseOptions.Description.Dictionary); context.Accept();
} }
if (PriorHandler != null) if (PriorHandler != null)
@ -341,7 +341,7 @@ namespace Microsoft.AspNet.Authentication
} }
} }
public virtual void SignOut(ISignOutContext context) public virtual void SignOut(SignOutContext context)
{ {
if (ShouldHandleScheme(context.AuthenticationScheme)) if (ShouldHandleScheme(context.AuthenticationScheme))
{ {
@ -356,7 +356,7 @@ namespace Microsoft.AspNet.Authentication
} }
} }
public virtual void Challenge(IChallengeContext context) public virtual void Challenge(ChallengeContext context)
{ {
if (ShouldHandleScheme(context.AuthenticationScheme)) if (ShouldHandleScheme(context.AuthenticationScheme))
{ {
@ -414,7 +414,7 @@ namespace Microsoft.AspNet.Authentication
Secure = Request.IsHttps Secure = Request.IsHttps
}; };
properties.Dictionary[correlationKey] = correlationId; properties.Items[correlationKey] = correlationId;
Response.Cookies.Append(correlationKey, correlationId, cookieOptions); Response.Cookies.Append(correlationKey, correlationId, cookieOptions);
} }
@ -437,7 +437,7 @@ namespace Microsoft.AspNet.Authentication
Response.Cookies.Delete(correlationKey, cookieOptions); Response.Cookies.Delete(correlationKey, cookieOptions);
string correlationExtra; string correlationExtra;
if (!properties.Dictionary.TryGetValue( if (!properties.Items.TryGetValue(
correlationKey, correlationKey,
out correlationExtra)) out correlationExtra))
{ {
@ -445,7 +445,7 @@ namespace Microsoft.AspNet.Authentication
return false; return false;
} }
properties.Dictionary.Remove(correlationKey); properties.Items.Remove(correlationKey);
if (!string.Equals(correlationCookie, correlationExtra, StringComparison.Ordinal)) if (!string.Equals(correlationCookie, correlationExtra, StringComparison.Ordinal))
{ {

View File

@ -22,24 +22,24 @@ namespace Microsoft.AspNet.Authentication
public IAuthenticationHandler PriorHandler { get; set; } public IAuthenticationHandler PriorHandler { get; set; }
private void ApplyTransform(IAuthenticateContext context) private void ApplyTransform(AuthenticateContext context)
{ {
if (_transform != null) if (_transform != null)
{ {
// REVIEW: this cast seems really bad (missing interface way to get the result back out?) // REVIEW: this cast seems really bad (missing interface way to get the result back out?)
var authContext = context as AuthenticateContext; var authContext = context as AuthenticateContext;
if (authContext?.Result?.Principal != null) if (authContext?.Principal != null)
{ {
context.Authenticated( context.Authenticated(
_transform.Invoke(authContext.Result.Principal), _transform.Invoke(authContext.Principal),
authContext.Result.Properties.Dictionary, authContext.Properties,
authContext.Result.Description.Dictionary); authContext.Description);
} }
} }
} }
public void Authenticate(IAuthenticateContext context) public void Authenticate(AuthenticateContext context)
{ {
if (PriorHandler != null) if (PriorHandler != null)
{ {
@ -48,7 +48,7 @@ namespace Microsoft.AspNet.Authentication
} }
} }
public async Task AuthenticateAsync(IAuthenticateContext context) public async Task AuthenticateAsync(AuthenticateContext context)
{ {
if (PriorHandler != null) if (PriorHandler != null)
{ {
@ -57,7 +57,7 @@ namespace Microsoft.AspNet.Authentication
} }
} }
public void Challenge(IChallengeContext context) public void Challenge(ChallengeContext context)
{ {
if (PriorHandler != null) if (PriorHandler != null)
{ {
@ -65,7 +65,7 @@ namespace Microsoft.AspNet.Authentication
} }
} }
public void GetDescriptions(IDescribeSchemesContext context) public void GetDescriptions(DescribeSchemesContext context)
{ {
if (PriorHandler != null) if (PriorHandler != null)
{ {
@ -73,7 +73,7 @@ namespace Microsoft.AspNet.Authentication
} }
} }
public void SignIn(ISignInContext context) public void SignIn(SignInContext context)
{ {
if (PriorHandler != null) if (PriorHandler != null)
{ {
@ -81,7 +81,7 @@ namespace Microsoft.AspNet.Authentication
} }
} }
public void SignOut(ISignOutContext context) public void SignOut(SignOutContext context)
{ {
if (PriorHandler != null) if (PriorHandler != null)
{ {

View File

@ -44,8 +44,8 @@ namespace Microsoft.AspNet.Authentication.DataHandler.Serializer
public static void Write([NotNull] BinaryWriter writer, [NotNull] AuthenticationProperties properties) public static void Write([NotNull] BinaryWriter writer, [NotNull] AuthenticationProperties properties)
{ {
writer.Write(FormatVersion); writer.Write(FormatVersion);
writer.Write(properties.Dictionary.Count); writer.Write(properties.Items.Count);
foreach (var kv in properties.Dictionary) foreach (var kv in properties.Items)
{ {
writer.Write(kv.Key); writer.Write(kv.Key);
writer.Write(kv.Value); writer.Write(kv.Value);

View File

@ -1,20 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Security.Claims;
using Microsoft.AspNet.Http.Authentication;
namespace Microsoft.AspNet.Authentication
{
public class SignInContext
{
public SignInContext(ClaimsPrincipal principal, AuthenticationProperties properties)
{
Principal = principal;
Properties = properties;
}
public ClaimsPrincipal Principal { get; private set; }
public AuthenticationProperties Properties { get; private set; }
}
}

View File

@ -79,7 +79,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
private Task SignInAsAlice(HttpContext context) private Task SignInAsAlice(HttpContext context)
{ {
context.Response.SignIn("Cookies", context.Authentication.SignIn("Cookies",
new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("Alice", "Cookies"))), new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("Alice", "Cookies"))),
new AuthenticationProperties()); new AuthenticationProperties());
return Task.FromResult<object>(null); return Task.FromResult<object>(null);
@ -87,7 +87,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
private Task SignInAsWrong(HttpContext context) private Task SignInAsWrong(HttpContext context)
{ {
context.Response.SignIn("Oops", context.Authentication.SignIn("Oops",
new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("Alice", "Cookies"))), new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("Alice", "Cookies"))),
new AuthenticationProperties()); new AuthenticationProperties());
return Task.FromResult<object>(null); return Task.FromResult<object>(null);
@ -95,7 +95,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
private Task SignOutAsWrong(HttpContext context) private Task SignOutAsWrong(HttpContext context)
{ {
context.Response.SignOut("Oops"); context.Authentication.SignOut("Oops");
return Task.FromResult<object>(null); return Task.FromResult<object>(null);
} }
@ -305,7 +305,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
}, },
context => context =>
{ {
context.Response.SignIn("Cookies", context.Authentication.SignIn("Cookies",
new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("Alice", "Cookies"))), new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("Alice", "Cookies"))),
new AuthenticationProperties() { ExpiresUtc = clock.UtcNow.Add(TimeSpan.FromMinutes(5)) }); new AuthenticationProperties() { ExpiresUtc = clock.UtcNow.Add(TimeSpan.FromMinutes(5)) });
return Task.FromResult<object>(null); return Task.FromResult<object>(null);
@ -435,7 +435,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
context => context =>
{ {
Assert.Equal(new PathString("/base"), context.Request.PathBase); Assert.Equal(new PathString("/base"), context.Request.PathBase);
context.Response.SignIn("Cookies", context.Authentication.SignIn("Cookies",
new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("Alice", "Cookies")))); new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("Alice", "Cookies"))));
return Task.FromResult<object>(null); return Task.FromResult<object>(null);
}, },
@ -545,12 +545,12 @@ namespace Microsoft.AspNet.Authentication.Cookies
else if (req.Path == new PathString("/unauthorized")) else if (req.Path == new PathString("/unauthorized"))
{ {
// Simulate Authorization failure // Simulate Authorization failure
var result = await context.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme); var result = await context.Authentication.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme);
res.Challenge(CookieAuthenticationDefaults.AuthenticationScheme); context.Authentication.Challenge(CookieAuthenticationDefaults.AuthenticationScheme);
} }
else if (req.Path == new PathString("/protected/CustomRedirect")) else if (req.Path == new PathString("/protected/CustomRedirect"))
{ {
context.Response.Challenge(new AuthenticationProperties() { RedirectUri = "/CustomRedirect" }); context.Authentication.Challenge(new AuthenticationProperties() { RedirectUri = "/CustomRedirect" });
} }
else if (req.Path == new PathString("/me")) else if (req.Path == new PathString("/me"))
{ {
@ -558,7 +558,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
} }
else if (req.Path.StartsWithSegments(new PathString("/me"), out remainder)) else if (req.Path.StartsWithSegments(new PathString("/me"), out remainder))
{ {
var result = await context.AuthenticateAsync(remainder.Value.Substring(1)); var result = await context.Authentication.AuthenticateAsync(remainder.Value.Substring(1));
Describe(res, result); Describe(res, result);
} }
else if (req.Path == new PathString("/testpath") && testpath != null) else if (req.Path == new PathString("/testpath") && testpath != null)
@ -594,7 +594,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
} }
if (result != null && result.Properties != null) if (result != null && result.Properties != null)
{ {
xml.Add(result.Properties.Dictionary.Select(extra => new XElement("extra", new XAttribute("type", extra.Key), new XAttribute("value", extra.Value)))); xml.Add(result.Properties.Items.Select(extra => new XElement("extra", new XAttribute("type", extra.Key), new XAttribute("value", extra.Value))));
} }
using (var memory = new MemoryStream()) using (var memory = new MemoryStream())
{ {

View File

@ -55,7 +55,7 @@ namespace Microsoft.AspNet.Authentication.Facebook
}, },
context => context =>
{ {
context.Response.Challenge("Facebook"); context.Authentication.Challenge("Facebook");
return true; return true;
}); });
var transaction = await SendAsync(server, "http://example.com/challenge"); var transaction = await SendAsync(server, "http://example.com/challenge");
@ -93,7 +93,7 @@ namespace Microsoft.AspNet.Authentication.Facebook
}, },
context => context =>
{ {
context.Response.Challenge("Facebook"); context.Authentication.Challenge("Facebook");
return true; return true;
}); });
var transaction = await SendAsync(server, "http://example.com/challenge"); var transaction = await SendAsync(server, "http://example.com/challenge");

View File

@ -142,14 +142,14 @@ namespace Microsoft.AspNet.Authentication.Google
var res = context.Response; var res = context.Response;
if (req.Path == new PathString("/challenge2")) if (req.Path == new PathString("/challenge2"))
{ {
res.Challenge(new AuthenticationProperties( context.Authentication.Challenge("Google", new AuthenticationProperties(
new Dictionary<string, string>() new Dictionary<string, string>()
{ {
{ "scope", "https://www.googleapis.com/auth/plus.login" }, { "scope", "https://www.googleapis.com/auth/plus.login" },
{ "access_type", "offline" }, { "access_type", "offline" },
{ "approval_prompt", "force" }, { "approval_prompt", "force" },
{ "login_hint", "test@example.com" } { "login_hint", "test@example.com" }
}), "Google"); }));
res.StatusCode = 401; res.StatusCode = 401;
} }
@ -280,7 +280,7 @@ namespace Microsoft.AspNet.Authentication.Google
var properties = new AuthenticationProperties(); var properties = new AuthenticationProperties();
var correlationKey = ".AspNet.Correlation.Google"; var correlationKey = ".AspNet.Correlation.Google";
var correlationValue = "TestCorrelationId"; var correlationValue = "TestCorrelationId";
properties.Dictionary.Add(correlationKey, correlationValue); properties.Items.Add(correlationKey, correlationValue);
properties.RedirectUri = "/me"; properties.RedirectUri = "/me";
var state = stateFormat.Protect(properties); var state = stateFormat.Protect(properties);
var transaction = await SendAsync(server, var transaction = await SendAsync(server,
@ -325,7 +325,7 @@ namespace Microsoft.AspNet.Authentication.Google
var properties = new AuthenticationProperties(); var properties = new AuthenticationProperties();
var correlationKey = ".AspNet.Correlation.Google"; var correlationKey = ".AspNet.Correlation.Google";
var correlationValue = "TestCorrelationId"; var correlationValue = "TestCorrelationId";
properties.Dictionary.Add(correlationKey, correlationValue); properties.Items.Add(correlationKey, correlationValue);
properties.RedirectUri = "/me"; properties.RedirectUri = "/me";
var state = stateFormat.Protect(properties); var state = stateFormat.Protect(properties);
var transaction = await SendAsync(server, var transaction = await SendAsync(server,
@ -355,7 +355,7 @@ namespace Microsoft.AspNet.Authentication.Google
var properties = new AuthenticationProperties(); var properties = new AuthenticationProperties();
var correlationKey = ".AspNet.Correlation.Google"; var correlationKey = ".AspNet.Correlation.Google";
var correlationValue = "TestCorrelationId"; var correlationValue = "TestCorrelationId";
properties.Dictionary.Add(correlationKey, correlationValue); properties.Items.Add(correlationKey, correlationValue);
properties.RedirectUri = "/me"; properties.RedirectUri = "/me";
var state = stateFormat.Protect(properties); var state = stateFormat.Protect(properties);
var transaction = await SendAsync(server, var transaction = await SendAsync(server,
@ -427,7 +427,7 @@ namespace Microsoft.AspNet.Authentication.Google
var properties = new AuthenticationProperties(); var properties = new AuthenticationProperties();
var correlationKey = ".AspNet.Correlation.Google"; var correlationKey = ".AspNet.Correlation.Google";
var correlationValue = "TestCorrelationId"; var correlationValue = "TestCorrelationId";
properties.Dictionary.Add(correlationKey, correlationValue); properties.Items.Add(correlationKey, correlationValue);
properties.RedirectUri = "/me"; properties.RedirectUri = "/me";
var state = stateFormat.Protect(properties); var state = stateFormat.Protect(properties);
var transaction = await SendAsync(server, var transaction = await SendAsync(server,
@ -497,7 +497,7 @@ namespace Microsoft.AspNet.Authentication.Google
var res = context.Response; var res = context.Response;
if (req.Path == new PathString("/challenge")) if (req.Path == new PathString("/challenge"))
{ {
res.Challenge("Google"); context.Authentication.Challenge("Google");
res.StatusCode = 401; res.StatusCode = 401;
} }
else if (req.Path == new PathString("/me")) else if (req.Path == new PathString("/me"))
@ -507,14 +507,14 @@ namespace Microsoft.AspNet.Authentication.Google
else if (req.Path == new PathString("/unauthorized")) else if (req.Path == new PathString("/unauthorized"))
{ {
// Simulate Authorization failure // Simulate Authorization failure
var result = await context.AuthenticateAsync("Google"); var result = await context.Authentication.AuthenticateAsync("Google");
res.Challenge("Google"); context.Authentication.Challenge("Google");
} }
else if (req.Path == new PathString("/unauthorizedAuto")) else if (req.Path == new PathString("/unauthorizedAuto"))
{ {
var result = await context.AuthenticateAsync("Google"); var result = await context.Authentication.AuthenticateAsync("Google");
res.StatusCode = 401; res.StatusCode = 401;
res.Challenge(); context.Authentication.Challenge();
} }
else if (req.Path == new PathString("/401")) else if (req.Path == new PathString("/401"))
{ {

View File

@ -46,7 +46,7 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount
}, },
context => context =>
{ {
context.Response.Challenge("Microsoft"); context.Authentication.Challenge("Microsoft");
return true; return true;
}); });
var transaction = await SendAsync(server, "http://example.com/challenge"); var transaction = await SendAsync(server, "http://example.com/challenge");
@ -66,7 +66,7 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount
}, },
context => context =>
{ {
context.Response.Challenge("Microsoft"); context.Authentication.Challenge("Microsoft");
return true; return true;
}); });
var transaction = await SendAsync(server, "http://example.com/challenge"); var transaction = await SendAsync(server, "http://example.com/challenge");
@ -140,7 +140,7 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount
var properties = new AuthenticationProperties(); var properties = new AuthenticationProperties();
var correlationKey = ".AspNet.Correlation.Microsoft"; var correlationKey = ".AspNet.Correlation.Microsoft";
var correlationValue = "TestCorrelationId"; var correlationValue = "TestCorrelationId";
properties.Dictionary.Add(correlationKey, correlationValue); properties.Items.Add(correlationKey, correlationValue);
properties.RedirectUri = "/me"; properties.RedirectUri = "/me";
var state = stateFormat.Protect(properties); var state = stateFormat.Protect(properties);
var transaction = await SendAsync(server, var transaction = await SendAsync(server,

View File

@ -326,8 +326,8 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
else if (context.Request.Path == new PathString("/unauthorized")) else if (context.Request.Path == new PathString("/unauthorized"))
{ {
// Simulate Authorization failure // Simulate Authorization failure
var result = await context.AuthenticateAsync(OAuthBearerAuthenticationDefaults.AuthenticationScheme); var result = await context.Authentication.AuthenticateAsync(OAuthBearerAuthenticationDefaults.AuthenticationScheme);
context.Response.Challenge(OAuthBearerAuthenticationDefaults.AuthenticationScheme); context.Authentication.Challenge(OAuthBearerAuthenticationDefaults.AuthenticationScheme);
} }
else else

View File

@ -493,28 +493,6 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
} }
} }
public class OpenIdConnectAuthenticationContext : IAuthenticateContext
{
public OpenIdConnectAuthenticationContext(string scheme = null)
{
AuthenticationScheme = scheme ?? OpenIdConnectAuthenticationDefaults.AuthenticationScheme;
}
public string AuthenticationScheme
{
get;
set;
}
public void Authenticated(ClaimsPrincipal principal, IDictionary<string, string> properties, IDictionary<string, object> description)
{
}
public void NotAuthenticated()
{
}
}
/// <summary> /// <summary>
/// Provides a Facade over IOptions /// Provides a Facade over IOptions
/// </summary> /// </summary>
@ -576,7 +554,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
return true; return true;
} }
public override void Challenge(IChallengeContext context) public override void Challenge(ChallengeContext context)
{ {
} }

View File

@ -205,21 +205,21 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
var res = context.Response; var res = context.Response;
if (req.Path == new PathString("/challenge")) if (req.Path == new PathString("/challenge"))
{ {
res.Challenge("OpenIdConnect"); context.Authentication.Challenge("OpenIdConnect");
res.StatusCode = 401; res.StatusCode = 401;
} }
else if (req.Path == new PathString("/signin")) else if (req.Path == new PathString("/signin"))
{ {
// REVIEW: this used to just be res.SignIn() // REVIEW: this used to just be res.SignIn()
res.SignIn("OpenIdConnect", new ClaimsPrincipal()); context.Authentication.SignIn("OpenIdConnect", new ClaimsPrincipal());
} }
else if (req.Path == new PathString("/signout")) else if (req.Path == new PathString("/signout"))
{ {
res.SignOut(OpenIdConnectAuthenticationDefaults.AuthenticationScheme); context.Authentication.SignOut(OpenIdConnectAuthenticationDefaults.AuthenticationScheme);
} }
else if (req.Path == new PathString("/signout_with_specific_redirect_uri")) else if (req.Path == new PathString("/signout_with_specific_redirect_uri"))
{ {
res.SignOut( context.Authentication.SignOut(
OpenIdConnectAuthenticationDefaults.AuthenticationScheme, OpenIdConnectAuthenticationDefaults.AuthenticationScheme,
new AuthenticationProperties() { RedirectUri = "http://www.example.com/specific_redirect_uri" }); new AuthenticationProperties() { RedirectUri = "http://www.example.com/specific_redirect_uri" });
} }

View File

@ -54,7 +54,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
}), }),
context => context =>
{ {
context.Response.Challenge("Twitter"); context.Authentication.Challenge("Twitter");
return true; return true;
}); });
var transaction = await SendAsync(server, "http://example.com/challenge"); var transaction = await SendAsync(server, "http://example.com/challenge");
@ -92,7 +92,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
}), }),
context => context =>
{ {
context.Response.Challenge("Twitter"); context.Authentication.Challenge("Twitter");
return true; return true;
}); });
var transaction = await SendAsync(server, "http://example.com/challenge"); var transaction = await SendAsync(server, "http://example.com/challenge");