Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit 63fc18b

Browse files
committed
React to auth feature API changes.
1 parent 87c31c5 commit 63fc18b

File tree

21 files changed

+88
-130
lines changed

21 files changed

+88
-130
lines changed

samples/CookieSample/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
2828
if (string.IsNullOrEmpty(context.User.Identity.Name))
2929
{
3030
var user = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "bob") }));
31-
context.Response.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, user);
31+
context.Authentication.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, user);
3232
context.Response.ContentType = "text/plain";
3333
await context.Response.WriteAsync("Hello First timer");
3434
return;

samples/CookieSessionSample/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
3636
{
3737
claims.Add(new Claim(ClaimTypes.Role, "SomeRandomGroup" + i, ClaimValueTypes.String, "IssuedByBob", "OriginalIssuerJoe"));
3838
}
39-
context.Response.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(new ClaimsIdentity(claims)));
39+
context.Authentication.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(new ClaimsIdentity(claims)));
4040
context.Response.ContentType = "text/plain";
4141
await context.Response.WriteAsync("Hello First timer");
4242
return;

samples/OpenIdConnectSample/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
4040
{
4141
if (string.IsNullOrEmpty(context.User.Identity.Name))
4242
{
43-
context.Response.Challenge(new AuthenticationProperties { RedirectUri = "/" }, OpenIdConnectAuthenticationDefaults.AuthenticationScheme);
43+
context.Authentication.Challenge(OpenIdConnectAuthenticationDefaults.AuthenticationScheme, new AuthenticationProperties { RedirectUri = "/" });
4444

4545
context.Response.ContentType = "text/plain";
4646
await context.Response.WriteAsync("Hello First timer");

samples/SocialSample/Startup.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,14 @@ dnx . web
188188
{
189189
// By default the client will be redirect back to the URL that issued the challenge (/login?authtype=foo),
190190
// send them to the home page instead (/).
191-
context.Response.Challenge(new AuthenticationProperties() { RedirectUri = "/" }, authType);
191+
context.Authentication.Challenge(authType, new AuthenticationProperties() { RedirectUri = "/" });
192192
return;
193193
}
194194

195195
context.Response.ContentType = "text/html";
196196
await context.Response.WriteAsync("<html><body>");
197197
await context.Response.WriteAsync("Choose an authentication scheme: <br>");
198-
foreach (var type in context.GetAuthenticationSchemes())
198+
foreach (var type in context.Authentication.GetAuthenticationSchemes())
199199
{
200200
await context.Response.WriteAsync("<a href=\"?authscheme=" + type.AuthenticationScheme + "\">" + (type.Caption ?? "(suppressed)") + "</a><br>");
201201
}
@@ -208,7 +208,7 @@ dnx . web
208208
{
209209
signoutApp.Run(async context =>
210210
{
211-
context.Response.SignOut(CookieAuthenticationDefaults.AuthenticationScheme);
211+
context.Authentication.SignOut(CookieAuthenticationDefaults.AuthenticationScheme);
212212
context.Response.ContentType = "text/html";
213213
await context.Response.WriteAsync("<html><body>");
214214
await context.Response.WriteAsync("You have been logged out. Goodbye " + context.User.Identity.Name + "<br>");
@@ -223,7 +223,7 @@ dnx . web
223223
if (string.IsNullOrEmpty(context.User.Identity.Name))
224224
{
225225
// The cookie middleware will intercept this 401 and redirect to /login
226-
context.Response.Challenge();
226+
context.Authentication.Challenge();
227227
return;
228228
}
229229
await next();

src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationHandler.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,23 +157,23 @@ protected override async Task ApplyResponseGrantAsync()
157157
Options,
158158
Options.AuthenticationScheme,
159159
signin.Principal,
160-
signin.Properties,
160+
new AuthenticationProperties(signin.Properties),
161161
cookieOptions);
162162

163163
DateTimeOffset issuedUtc;
164-
if (signin.Properties.IssuedUtc.HasValue)
164+
if (signInContext.Properties.IssuedUtc.HasValue)
165165
{
166-
issuedUtc = signin.Properties.IssuedUtc.Value;
166+
issuedUtc = signInContext.Properties.IssuedUtc.Value;
167167
}
168168
else
169169
{
170170
issuedUtc = Options.SystemClock.UtcNow;
171-
signin.Properties.IssuedUtc = issuedUtc;
171+
signInContext.Properties.IssuedUtc = issuedUtc;
172172
}
173173

174-
if (!signin.Properties.ExpiresUtc.HasValue)
174+
if (!signInContext.Properties.ExpiresUtc.HasValue)
175175
{
176-
signin.Properties.ExpiresUtc = issuedUtc.Add(Options.ExpireTimeSpan);
176+
signInContext.Properties.ExpiresUtc = issuedUtc.Add(Options.ExpireTimeSpan);
177177
}
178178

179179
Options.Notifications.ResponseSignIn(signInContext);
@@ -226,7 +226,7 @@ protected override async Task ApplyResponseGrantAsync()
226226
Context,
227227
Options,
228228
cookieOptions);
229-
229+
230230
Options.Notifications.ResponseSignOut(context);
231231

232232
Options.CookieManager.DeleteCookie(

src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ private static void AddQueryString(IDictionary<string, string> queryStrings, Aut
102102
string name, string defaultValue = null)
103103
{
104104
string value;
105-
if (!properties.Dictionary.TryGetValue(name, out value))
105+
if (!properties.Items.TryGetValue(name, out value))
106106
{
107107
value = defaultValue;
108108
}
109109
else
110110
{
111111
// Remove the parameter from AuthenticationProperties so it won't be serialized to state parameter
112-
properties.Dictionary.Remove(name);
112+
properties.Items.Remove(name);
113113
}
114114

115115
if (value == null)

src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public async Task<bool> InvokeReturnPathAsync()
5656

5757
if (context.SignInScheme != null && context.Principal != null)
5858
{
59-
Context.Response.SignIn(context.SignInScheme, context.Principal, context.Properties);
59+
Context.Authentication.SignIn(context.SignInScheme, context.Principal, context.Properties);
6060
}
6161

6262
if (!context.IsRequestCompleted && context.RedirectUri != null)

src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationHandler.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ protected override async Task ApplyResponseChallengeAsync()
161161
// When redeeming a 'code' for an AccessToken, this value is needed
162162
if (!string.IsNullOrWhiteSpace(Options.RedirectUri))
163163
{
164-
properties.Dictionary.Add(OpenIdConnectAuthenticationDefaults.RedirectUriUsedForCodeKey, Options.RedirectUri);
164+
properties.Items.Add(OpenIdConnectAuthenticationDefaults.RedirectUriUsedForCodeKey, Options.RedirectUri);
165165
}
166166

167167
if (_configuration == null && Options.ConfigurationManager != null)
@@ -385,12 +385,12 @@ protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
385385
ticket = new AuthenticationTicket(principal, properties, Options.AuthenticationScheme);
386386
if (!string.IsNullOrWhiteSpace(message.SessionState))
387387
{
388-
ticket.Properties.Dictionary[OpenIdConnectSessionProperties.SessionState] = message.SessionState;
388+
ticket.Properties.Items[OpenIdConnectSessionProperties.SessionState] = message.SessionState;
389389
}
390390

391391
if (_configuration != null && !string.IsNullOrWhiteSpace(_configuration.CheckSessionIframe))
392392
{
393-
ticket.Properties.Dictionary[OpenIdConnectSessionProperties.CheckSessionIFrame] = _configuration.CheckSessionIframe;
393+
ticket.Properties.Items[OpenIdConnectSessionProperties.CheckSessionIFrame] = _configuration.CheckSessionIframe;
394394
}
395395

396396
// Rename?
@@ -466,8 +466,8 @@ protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
466466
Code = message.Code,
467467
JwtSecurityToken = jwt,
468468
ProtocolMessage = message,
469-
RedirectUri = ticket.Properties.Dictionary.ContainsKey(OpenIdConnectAuthenticationDefaults.RedirectUriUsedForCodeKey) ?
470-
ticket.Properties.Dictionary[OpenIdConnectAuthenticationDefaults.RedirectUriUsedForCodeKey] : string.Empty,
469+
RedirectUri = ticket.Properties.Items.ContainsKey(OpenIdConnectAuthenticationDefaults.RedirectUriUsedForCodeKey) ?
470+
ticket.Properties.Items[OpenIdConnectAuthenticationDefaults.RedirectUriUsedForCodeKey] : string.Empty,
471471
};
472472

473473
await Options.Notifications.AuthorizationCodeReceived(authorizationCodeReceivedNotification);
@@ -632,7 +632,7 @@ private async Task<bool> InvokeReplyPathAsync()
632632
{
633633
if (ticket.Principal != null)
634634
{
635-
Request.HttpContext.Response.SignIn(Options.SignInScheme, ticket.Principal, ticket.Properties);
635+
Request.HttpContext.Authentication.SignIn(Options.SignInScheme, ticket.Principal, ticket.Properties);
636636
}
637637

638638
// Redirect back to the original secured resource, if any.

src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public async Task<bool> InvokeReturnPathAsync()
208208

209209
if (context.SignInScheme != null && context.Principal != null)
210210
{
211-
Context.Response.SignIn(context.SignInScheme, context.Principal, context.Properties);
211+
Context.Authentication.SignIn(context.SignInScheme, context.Principal, context.Properties);
212212
}
213213

214214
if (!context.IsRequestCompleted && context.RedirectUri != null)

src/Microsoft.AspNet.Authentication/AuthenticationHandler.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public abstract class AuthenticationHandler : IAuthenticationHandler
3131

3232
private AuthenticationOptions _baseOptions;
3333

34-
protected IChallengeContext ChallengeContext { get; set; }
34+
protected ChallengeContext ChallengeContext { get; set; }
3535
protected SignInContext SignInContext { get; set; }
36-
protected ISignOutContext SignOutContext { get; set; }
36+
protected SignOutContext SignOutContext { get; set; }
3737

3838
protected HttpContext Context { get; private set; }
3939

@@ -145,25 +145,25 @@ public virtual Task<bool> InvokeAsync()
145145
return Task.FromResult(false);
146146
}
147147

148-
public virtual void GetDescriptions(IDescribeSchemesContext describeContext)
148+
public virtual void GetDescriptions(DescribeSchemesContext describeContext)
149149
{
150-
describeContext.Accept(BaseOptions.Description.Dictionary);
150+
describeContext.Accept(BaseOptions.Description.Items);
151151

152152
if (PriorHandler != null)
153153
{
154154
PriorHandler.GetDescriptions(describeContext);
155155
}
156156
}
157157

158-
public virtual void Authenticate(IAuthenticateContext context)
158+
public virtual void Authenticate(AuthenticateContext context)
159159
{
160160
if (ShouldHandleScheme(context.AuthenticationScheme))
161161
{
162162
var ticket = Authenticate();
163163
if (ticket?.Principal != null)
164164
{
165165
AuthenticateCalled = true;
166-
context.Authenticated(ticket.Principal, ticket.Properties.Dictionary, BaseOptions.Description.Dictionary);
166+
context.Authenticated(ticket.Principal, ticket.Properties.Items, BaseOptions.Description.Items);
167167
}
168168
else
169169
{
@@ -177,15 +177,15 @@ public virtual void Authenticate(IAuthenticateContext context)
177177
}
178178
}
179179

180-
public virtual async Task AuthenticateAsync(IAuthenticateContext context)
180+
public virtual async Task AuthenticateAsync(AuthenticateContext context)
181181
{
182182
if (ShouldHandleScheme(context.AuthenticationScheme))
183183
{
184184
var ticket = await AuthenticateAsync();
185185
if (ticket?.Principal != null)
186186
{
187187
AuthenticateCalled = true;
188-
context.Authenticated(ticket.Principal, ticket.Properties.Dictionary, BaseOptions.Description.Dictionary);
188+
context.Authenticated(ticket.Principal, ticket.Properties.Items, BaseOptions.Description.Items);
189189
}
190190
else
191191
{
@@ -326,13 +326,13 @@ protected virtual Task ApplyResponseGrantAsync()
326326
return Task.FromResult(0);
327327
}
328328

329-
public virtual void SignIn(ISignInContext context)
329+
public virtual void SignIn(SignInContext context)
330330
{
331331
if (ShouldHandleScheme(context.AuthenticationScheme))
332332
{
333-
SignInContext = new SignInContext(context.Principal, new AuthenticationProperties(context.Properties));
333+
SignInContext = context;
334334
SignOutContext = null;
335-
context.Accept(BaseOptions.Description.Dictionary);
335+
context.Accept();
336336
}
337337

338338
if (PriorHandler != null)
@@ -341,7 +341,7 @@ public virtual void SignIn(ISignInContext context)
341341
}
342342
}
343343

344-
public virtual void SignOut(ISignOutContext context)
344+
public virtual void SignOut(SignOutContext context)
345345
{
346346
if (ShouldHandleScheme(context.AuthenticationScheme))
347347
{
@@ -356,7 +356,7 @@ public virtual void SignOut(ISignOutContext context)
356356
}
357357
}
358358

359-
public virtual void Challenge(IChallengeContext context)
359+
public virtual void Challenge(ChallengeContext context)
360360
{
361361
if (ShouldHandleScheme(context.AuthenticationScheme))
362362
{
@@ -414,7 +414,7 @@ protected void GenerateCorrelationId([NotNull] AuthenticationProperties properti
414414
Secure = Request.IsHttps
415415
};
416416

417-
properties.Dictionary[correlationKey] = correlationId;
417+
properties.Items[correlationKey] = correlationId;
418418

419419
Response.Cookies.Append(correlationKey, correlationId, cookieOptions);
420420
}
@@ -437,15 +437,15 @@ protected bool ValidateCorrelationId([NotNull] AuthenticationProperties properti
437437
Response.Cookies.Delete(correlationKey, cookieOptions);
438438

439439
string correlationExtra;
440-
if (!properties.Dictionary.TryGetValue(
440+
if (!properties.Items.TryGetValue(
441441
correlationKey,
442442
out correlationExtra))
443443
{
444444
Logger.LogWarning("{0} state property not found.", correlationKey);
445445
return false;
446446
}
447447

448-
properties.Dictionary.Remove(correlationKey);
448+
properties.Items.Remove(correlationKey);
449449

450450
if (!string.Equals(correlationCookie, correlationExtra, StringComparison.Ordinal))
451451
{

src/Microsoft.AspNet.Authentication/ClaimsTransformationAuthenticationHandler.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,24 @@ public ClaimsTransformationAuthenticationHandler(Func<ClaimsPrincipal, ClaimsPri
2222

2323
public IAuthenticationHandler PriorHandler { get; set; }
2424

25-
private void ApplyTransform(IAuthenticateContext context)
25+
private void ApplyTransform(AuthenticateContext context)
2626
{
2727
if (_transform != null)
2828
{
2929
// REVIEW: this cast seems really bad (missing interface way to get the result back out?)
3030
var authContext = context as AuthenticateContext;
31-
if (authContext?.Result?.Principal != null)
31+
if (authContext?.Principal != null)
3232
{
3333
context.Authenticated(
34-
_transform.Invoke(authContext.Result.Principal),
35-
authContext.Result.Properties.Dictionary,
36-
authContext.Result.Description.Dictionary);
34+
_transform.Invoke(authContext.Principal),
35+
authContext.Properties,
36+
authContext.Description);
3737
}
3838
}
3939

4040
}
4141

42-
public void Authenticate(IAuthenticateContext context)
42+
public void Authenticate(AuthenticateContext context)
4343
{
4444
if (PriorHandler != null)
4545
{
@@ -48,7 +48,7 @@ public void Authenticate(IAuthenticateContext context)
4848
}
4949
}
5050

51-
public async Task AuthenticateAsync(IAuthenticateContext context)
51+
public async Task AuthenticateAsync(AuthenticateContext context)
5252
{
5353
if (PriorHandler != null)
5454
{
@@ -57,31 +57,31 @@ public async Task AuthenticateAsync(IAuthenticateContext context)
5757
}
5858
}
5959

60-
public void Challenge(IChallengeContext context)
60+
public void Challenge(ChallengeContext context)
6161
{
6262
if (PriorHandler != null)
6363
{
6464
PriorHandler.Challenge(context);
6565
}
6666
}
6767

68-
public void GetDescriptions(IDescribeSchemesContext context)
68+
public void GetDescriptions(DescribeSchemesContext context)
6969
{
7070
if (PriorHandler != null)
7171
{
7272
PriorHandler.GetDescriptions(context);
7373
}
7474
}
7575

76-
public void SignIn(ISignInContext context)
76+
public void SignIn(SignInContext context)
7777
{
7878
if (PriorHandler != null)
7979
{
8080
PriorHandler.SignIn(context);
8181
}
8282
}
8383

84-
public void SignOut(ISignOutContext context)
84+
public void SignOut(SignOutContext context)
8585
{
8686
if (PriorHandler != null)
8787
{

src/Microsoft.AspNet.Authentication/DataHandler/Serializer/PropertiesSerializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public AuthenticationProperties Deserialize(byte[] data)
4444
public static void Write([NotNull] BinaryWriter writer, [NotNull] AuthenticationProperties properties)
4545
{
4646
writer.Write(FormatVersion);
47-
writer.Write(properties.Dictionary.Count);
48-
foreach (var kv in properties.Dictionary)
47+
writer.Write(properties.Items.Count);
48+
foreach (var kv in properties.Items)
4949
{
5050
writer.Write(kv.Key);
5151
writer.Write(kv.Value);

0 commit comments

Comments
 (0)