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

Commit de1e876

Browse files
committed
Security -> Authentication
AuthN renames and design changes
1 parent 2f960b9 commit de1e876

25 files changed

+238
-235
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System;
54
using System.Collections.Generic;
6-
using System.Linq;
75
using System.Security.Claims;
8-
using System.Text;
9-
using System.Threading.Tasks;
10-
using Microsoft.AspNet.Http.Security;
11-
using Microsoft.AspNet.Http.Interfaces.Security;
6+
using Microsoft.AspNet.Http.Interfaces.Authentication;
7+
using Microsoft.AspNet.Http.Authentication;
128

13-
namespace Microsoft.AspNet.Http.Core.Security
9+
namespace Microsoft.AspNet.Http.Core.Authentication
1410
{
1511
public class AuthenticateContext : IAuthenticateContext
1612
{
1713
private List<AuthenticationResult> _results;
1814
private List<string> _accepted;
1915

20-
public AuthenticateContext([NotNull] IEnumerable<string> authenticationTypes)
16+
public AuthenticateContext([NotNull] IEnumerable<string> authenticationSchemes)
2117
{
22-
AuthenticationTypes = authenticationTypes;
18+
AuthenticationSchemes = authenticationSchemes;
2319
_results = new List<AuthenticationResult>();
2420
_accepted = new List<string>();
2521
}
2622

27-
public IEnumerable<string> AuthenticationTypes { get; private set; }
23+
public IEnumerable<string> AuthenticationSchemes { get; private set; }
2824

2925
public IEnumerable<AuthenticationResult> Results
3026
{
@@ -36,16 +32,16 @@ public IEnumerable<string> Accepted
3632
get { return _accepted; }
3733
}
3834

39-
public void Authenticated(ClaimsIdentity identity, IDictionary<string, string> properties, IDictionary<string, object> description)
35+
public void Authenticated(ClaimsPrincipal principal, IDictionary<string, string> properties, IDictionary<string, object> description)
4036
{
4137
var descrip = new AuthenticationDescription(description);
42-
_accepted.Add(descrip.AuthenticationType); // may not match identity.AuthType
43-
_results.Add(new AuthenticationResult(identity, new AuthenticationProperties(properties), descrip));
38+
_accepted.Add(descrip.AuthenticationScheme); // may not match identity.AuthType
39+
_results.Add(new AuthenticationResult(principal, new AuthenticationProperties(properties), descrip));
4440
}
4541

46-
public void NotAuthenticated(string authenticationType, IDictionary<string, string> properties, IDictionary<string, object> description)
42+
public void NotAuthenticated(string authenticationScheme, IDictionary<string, string> properties, IDictionary<string, object> description)
4743
{
48-
_accepted.Add(authenticationType);
44+
_accepted.Add(authenticationScheme);
4945
}
5046
}
5147
}

src/Microsoft.AspNet.Http.Core/Security/ChallengeContext.cs renamed to src/Microsoft.AspNet.Http.Core/Authentication/ChallengeContext.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,22 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.Linq;
7-
using System.Text;
8-
using System.Threading.Tasks;
9-
using Microsoft.AspNet.Http.Interfaces.Security;
6+
using Microsoft.AspNet.Http.Interfaces.Authentication;
107

11-
namespace Microsoft.AspNet.Http.Core.Security
8+
namespace Microsoft.AspNet.Http.Core.Authentication
129
{
1310
public class ChallengeContext : IChallengeContext
1411
{
1512
private List<string> _accepted;
1613

17-
public ChallengeContext([NotNull] IEnumerable<string> authenticationTypes, IDictionary<string, string> properties)
14+
public ChallengeContext([NotNull] IEnumerable<string> authenticationSchemes, IDictionary<string, string> properties)
1815
{
19-
AuthenticationTypes = authenticationTypes;
16+
AuthenticationSchemes = authenticationSchemes;
2017
Properties = properties ?? new Dictionary<string, string>(StringComparer.Ordinal);
2118
_accepted = new List<string>();
2219
}
2320

24-
public IEnumerable<string> AuthenticationTypes { get; private set; }
21+
public IEnumerable<string> AuthenticationSchemes { get; private set; }
2522

2623
public IDictionary<string, string> Properties { get; private set; }
2724

src/Microsoft.AspNet.Http.Core/Security/AuthTypeContext.cs renamed to src/Microsoft.AspNet.Http.Core/Authentication/DescribeSchemesContext.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System;
54
using System.Collections.Generic;
6-
using Microsoft.AspNet.Http.Security;
7-
using Microsoft.AspNet.Http.Interfaces.Security;
5+
using Microsoft.AspNet.Http.Authentication;
6+
using Microsoft.AspNet.Http.Interfaces.Authentication;
87

9-
namespace Microsoft.AspNet.Http.Core.Security
8+
namespace Microsoft.AspNet.Http.Core.Authentication
109
{
11-
public class AuthTypeContext : IAuthTypeContext
10+
public class DescribeSchemesContext : IDescribeSchemesContext
1211
{
1312
private List<AuthenticationDescription> _results;
1413

15-
public AuthTypeContext()
14+
public DescribeSchemesContext()
1615
{
1716
_results = new List<AuthenticationDescription>();
1817
}

src/Microsoft.AspNet.Http.Core/Security/HttpAuthenticationFeature.cs renamed to src/Microsoft.AspNet.Http.Core/Authentication/HttpAuthenticationFeature.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Security.Claims;
5-
using Microsoft.AspNet.Http.Interfaces.Security;
5+
using Microsoft.AspNet.Http.Interfaces.Authentication;
66

7-
namespace Microsoft.AspNet.Http.Core.Security
7+
namespace Microsoft.AspNet.Http.Core.Authentication
88
{
99
public class HttpAuthenticationFeature : IHttpAuthenticationFeature
1010
{
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Security.Claims;
7+
using Microsoft.AspNet.Http.Interfaces.Authentication;
8+
9+
namespace Microsoft.AspNet.Http.Core.Authentication
10+
{
11+
public class SignInContext : ISignInContext
12+
{
13+
private bool _accepted;
14+
15+
public SignInContext([NotNull] string authenticationScheme, [NotNull] ClaimsPrincipal principal, IDictionary<string, string> dictionary)
16+
{
17+
AuthenticationScheme = authenticationScheme;
18+
Principal = principal;
19+
Properties = dictionary ?? new Dictionary<string, string>(StringComparer.Ordinal);
20+
}
21+
22+
public ClaimsPrincipal Principal { get; }
23+
24+
public IDictionary<string, string> Properties { get; }
25+
26+
public string AuthenticationScheme { get; }
27+
28+
public bool Accepted
29+
{
30+
get { return _accepted; }
31+
}
32+
33+
public void Accept(IDictionary<string, object> description)
34+
{
35+
_accepted = true;
36+
}
37+
}
38+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using Microsoft.AspNet.Http.Interfaces.Authentication;
7+
8+
namespace Microsoft.AspNet.Http.Core.Authentication
9+
{
10+
public class SignOutContext : ISignOutContext
11+
{
12+
private bool _accepted;
13+
14+
public SignOutContext(string authenticationScheme)
15+
{
16+
AuthenticationScheme = authenticationScheme;
17+
}
18+
19+
public string AuthenticationScheme { get; }
20+
21+
public bool Accepted
22+
{
23+
get { return _accepted; }
24+
}
25+
26+
public void Accept()
27+
{
28+
_accepted = true;
29+
}
30+
}
31+
}

src/Microsoft.AspNet.Http.Core/DefaultHttpContext.cs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
using System.Threading;
1010
using System.Threading.Tasks;
1111
using Microsoft.AspNet.FeatureModel;
12-
using Microsoft.AspNet.Http;
13-
using Microsoft.AspNet.Http.Infrastructure;
14-
using Microsoft.AspNet.Http.Security;
15-
using Microsoft.AspNet.Http.Interfaces;
16-
using Microsoft.AspNet.Http.Interfaces.Security;
1712
using Microsoft.AspNet.Http.Core.Collections;
1813
using Microsoft.AspNet.Http.Core.Infrastructure;
19-
using Microsoft.AspNet.Http.Core.Security;
14+
using Microsoft.AspNet.Http.Core.Authentication;
15+
using Microsoft.AspNet.Http.Infrastructure;
16+
using Microsoft.AspNet.Http.Interfaces;
17+
using Microsoft.AspNet.Http.Interfaces.Authentication;
18+
using Microsoft.AspNet.Http.Authentication;
2019

2120
namespace Microsoft.AspNet.Http.Core
2221
{
@@ -201,54 +200,54 @@ public override void SetFeature(Type type, object instance)
201200
_features[type] = instance;
202201
}
203202

204-
public override IEnumerable<AuthenticationDescription> GetAuthenticationTypes()
203+
public override IEnumerable<AuthenticationDescription> GetAuthenticationSchemes()
205204
{
206205
var handler = HttpAuthenticationFeature.Handler;
207206
if (handler == null)
208207
{
209208
return new AuthenticationDescription[0];
210209
}
211210

212-
var authTypeContext = new AuthTypeContext();
213-
handler.GetDescriptions(authTypeContext);
214-
return authTypeContext.Results;
211+
var describeContext = new DescribeSchemesContext();
212+
handler.GetDescriptions(describeContext);
213+
return describeContext.Results;
215214
}
216215

217-
public override IEnumerable<AuthenticationResult> Authenticate([NotNull] IEnumerable<string> authenticationTypes)
216+
public override IEnumerable<AuthenticationResult> Authenticate([NotNull] IEnumerable<string> authenticationSchemes)
218217
{
219218
var handler = HttpAuthenticationFeature.Handler;
220219

221-
var authenticateContext = new AuthenticateContext(authenticationTypes);
220+
var authenticateContext = new AuthenticateContext(authenticationSchemes);
222221
if (handler != null)
223222
{
224223
handler.Authenticate(authenticateContext);
225224
}
226225

227226
// Verify all types ack'd
228-
IEnumerable<string> leftovers = authenticationTypes.Except(authenticateContext.Accepted);
227+
IEnumerable<string> leftovers = authenticationSchemes.Except(authenticateContext.Accepted);
229228
if (leftovers.Any())
230229
{
231-
throw new InvalidOperationException("The following authentication types were not accepted: " + string.Join(", ", leftovers));
230+
throw new InvalidOperationException("The following authentication schemes were not accepted: " + string.Join(", ", leftovers));
232231
}
233232

234233
return authenticateContext.Results;
235234
}
236235

237-
public override async Task<IEnumerable<AuthenticationResult>> AuthenticateAsync([NotNull] IEnumerable<string> authenticationTypes)
236+
public override async Task<IEnumerable<AuthenticationResult>> AuthenticateAsync([NotNull] IEnumerable<string> authenticationSchemes)
238237
{
239238
var handler = HttpAuthenticationFeature.Handler;
240239

241-
var authenticateContext = new AuthenticateContext(authenticationTypes);
240+
var authenticateContext = new AuthenticateContext(authenticationSchemes);
242241
if (handler != null)
243242
{
244243
await handler.AuthenticateAsync(authenticateContext);
245244
}
246245

247246
// Verify all types ack'd
248-
IEnumerable<string> leftovers = authenticationTypes.Except(authenticateContext.Accepted);
247+
IEnumerable<string> leftovers = authenticationSchemes.Except(authenticateContext.Accepted);
249248
if (leftovers.Any())
250249
{
251-
throw new InvalidOperationException("The following authentication types were not accepted: " + string.Join(", ", leftovers));
250+
throw new InvalidOperationException("The following authentication schemes were not accepted: " + string.Join(", ", leftovers));
252251
}
253252

254253
return authenticateContext.Results;
@@ -264,4 +263,4 @@ public override Task<WebSocket> AcceptWebSocketAsync(string subProtocol)
264263
return WebSocketFeature.AcceptAsync(new WebSocketAcceptContext() { SubProtocol = subProtocol } );
265264
}
266265
}
267-
}
266+
}

src/Microsoft.AspNet.Http.Core/DefaultHttpResponse.cs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@
66
using System.IO;
77
using System.Linq;
88
using System.Security.Claims;
9-
using System.Text;
10-
using System.Threading.Tasks;
11-
using Microsoft.AspNet.Http;
12-
using Microsoft.AspNet.Http.Infrastructure;
13-
using Microsoft.AspNet.Http.Security;
149
using Microsoft.AspNet.FeatureModel;
15-
using Microsoft.AspNet.Http.Interfaces;
16-
using Microsoft.AspNet.Http.Interfaces.Security;
1710
using Microsoft.AspNet.Http.Core.Collections;
1811
using Microsoft.AspNet.Http.Core.Infrastructure;
19-
using Microsoft.AspNet.Http.Core.Security;
12+
using Microsoft.AspNet.Http.Core.Authentication;
13+
using Microsoft.AspNet.Http.Infrastructure;
14+
using Microsoft.AspNet.Http.Interfaces;
15+
using Microsoft.AspNet.Http.Interfaces.Authentication;
16+
using Microsoft.AspNet.Http.Authentication;
2017

2118
namespace Microsoft.AspNet.Http.Core
2219
{
@@ -129,58 +126,56 @@ public override void Redirect(string location, bool permanent)
129126
Headers.Set(Constants.Headers.Location, location);
130127
}
131128

132-
public override void Challenge(AuthenticationProperties properties, [NotNull] IEnumerable<string> authenticationTypes)
129+
public override void Challenge(AuthenticationProperties properties, [NotNull] IEnumerable<string> authenticationSchemes)
133130
{
134131
HttpResponseFeature.StatusCode = 401;
135132
var handler = HttpAuthenticationFeature.Handler;
136133

137-
var challengeContext = new ChallengeContext(authenticationTypes, properties == null ? null : properties.Dictionary);
134+
var challengeContext = new ChallengeContext(authenticationSchemes, properties == null ? null : properties.Dictionary);
138135
if (handler != null)
139136
{
140137
handler.Challenge(challengeContext);
141138
}
142139

143140
// Verify all types ack'd
144-
IEnumerable<string> leftovers = authenticationTypes.Except(challengeContext.Accepted);
141+
IEnumerable<string> leftovers = authenticationSchemes.Except(challengeContext.Accepted);
145142
if (leftovers.Any())
146143
{
147144
throw new InvalidOperationException("The following authentication types were not accepted: " + string.Join(", ", leftovers));
148145
}
149146
}
150147

151-
public override void SignIn(AuthenticationProperties properties, [NotNull] IEnumerable<ClaimsIdentity> identities)
148+
public override void SignIn(string authenticationScheme, [NotNull] ClaimsPrincipal principal, AuthenticationProperties properties)
152149
{
153150
var handler = HttpAuthenticationFeature.Handler;
154151

155-
var signInContext = new SignInContext(identities, properties == null ? null : properties.Dictionary);
152+
var signInContext = new SignInContext(authenticationScheme, principal, properties == null ? null : properties.Dictionary);
156153
if (handler != null)
157154
{
158155
handler.SignIn(signInContext);
159156
}
160157

161158
// Verify all types ack'd
162-
IEnumerable<string> leftovers = identities.Select(identity => identity.AuthenticationType).Except(signInContext.Accepted);
163-
if (leftovers.Any())
159+
if (!signInContext.Accepted)
164160
{
165-
throw new InvalidOperationException("The following authentication types were not accepted: " + string.Join(", ", leftovers));
161+
throw new InvalidOperationException("The following authentication scheme was not accepted: " + authenticationScheme);
166162
}
167163
}
168164

169-
public override void SignOut([NotNull] IEnumerable<string> authenticationTypes)
165+
public override void SignOut(string authenticationScheme)
170166
{
171167
var handler = HttpAuthenticationFeature.Handler;
172168

173-
var signOutContext = new SignOutContext(authenticationTypes);
169+
var signOutContext = new SignOutContext(authenticationScheme);
174170
if (handler != null)
175171
{
176172
handler.SignOut(signOutContext);
177173
}
178174

179175
// Verify all types ack'd
180-
IEnumerable<string> leftovers = authenticationTypes.Except(signOutContext.Accepted);
181-
if (leftovers.Any())
176+
if (!string.IsNullOrWhiteSpace(authenticationScheme) && !signOutContext.Accepted)
182177
{
183-
throw new InvalidOperationException("The following authentication types were not accepted: " + string.Join(", ", leftovers));
178+
throw new InvalidOperationException("The following authentication scheme was not accepted: " + authenticationScheme);
184179
}
185180
}
186181
}

0 commit comments

Comments
 (0)