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

Commit 8be698e

Browse files
committed
#273 - Use POCOs for auth context objects.
1 parent db7969d commit 8be698e

15 files changed

+110
-194
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.Collections.Generic;
5+
using System.Security.Claims;
6+
using Microsoft.Framework.Internal;
7+
8+
namespace Microsoft.AspNet.Http.Authentication
9+
{
10+
public class AuthenticateContext
11+
{
12+
public AuthenticateContext([NotNull] string authenticationScheme)
13+
{
14+
AuthenticationScheme = authenticationScheme;
15+
}
16+
17+
public string AuthenticationScheme { get; }
18+
19+
public bool Accepted { get; private set; }
20+
21+
public ClaimsPrincipal Principal { get; private set; }
22+
23+
public IDictionary<string, string> Properties { get; private set; }
24+
25+
public IDictionary<string, object> Description { get; private set; }
26+
27+
public virtual void Authenticated(ClaimsPrincipal principal, IDictionary<string, string> properties, IDictionary<string, object> description)
28+
{
29+
Accepted = true;
30+
Principal = principal;
31+
Properties = properties;
32+
Description = description;
33+
}
34+
35+
public virtual void NotAuthenticated()
36+
{
37+
Accepted = true;
38+
}
39+
}
40+
}

src/Microsoft.AspNet.Http/Authentication/ChallengeContext.cs renamed to src/Microsoft.AspNet.Http.Interfaces/Authentication/ChallengeContext.cs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,26 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using Microsoft.Framework.Internal;
76

87
namespace Microsoft.AspNet.Http.Authentication
98
{
10-
public class ChallengeContext : IChallengeContext
9+
public class ChallengeContext
1110
{
12-
private bool _accepted;
13-
1411
public ChallengeContext(string authenticationScheme, IDictionary<string, string> properties)
1512
{
1613
AuthenticationScheme = authenticationScheme;
1714
Properties = properties ?? new Dictionary<string, string>(StringComparer.Ordinal);
18-
19-
// The default Challenge with no scheme is always accepted
20-
_accepted = string.IsNullOrEmpty(authenticationScheme);
2115
}
2216

23-
public string AuthenticationScheme { get; private set; }
17+
public string AuthenticationScheme { get; }
2418

25-
public IDictionary<string, string> Properties { get; private set; }
19+
public IDictionary<string, string> Properties { get; }
2620

27-
public bool Accepted
28-
{
29-
get { return _accepted; }
30-
}
21+
public bool Accepted { get; private set; }
3122

3223
public void Accept()
3324
{
34-
_accepted = true;
25+
Accepted = true;
3526
}
3627
}
37-
}
28+
}

src/Microsoft.AspNet.Http/Authentication/DescribeSchemesContext.cs renamed to src/Microsoft.AspNet.Http.Interfaces/Authentication/DescribeSchemesContext.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55

66
namespace Microsoft.AspNet.Http.Authentication
77
{
8-
public class DescribeSchemesContext : IDescribeSchemesContext
8+
public class DescribeSchemesContext
99
{
10-
private List<AuthenticationDescription> _results;
10+
private List<IDictionary<string, object>> _results;
1111

1212
public DescribeSchemesContext()
1313
{
14-
_results = new List<AuthenticationDescription>();
14+
_results = new List<IDictionary<string, object>>();
1515
}
1616

17-
public IEnumerable<AuthenticationDescription> Results
17+
public IEnumerable<IDictionary<string, object>> Results
1818
{
1919
get { return _results; }
2020
}
2121

2222
public void Accept(IDictionary<string, object> description)
2323
{
24-
_results.Add(new AuthenticationDescription(description));
24+
_results.Add(description);
2525
}
2626
}
27-
}
27+
}

src/Microsoft.AspNet.Http.Interfaces/Authentication/IAuthenticateContext.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/Microsoft.AspNet.Http.Interfaces/Authentication/IAuthenticationHandler.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ namespace Microsoft.AspNet.Http.Authentication
77
{
88
public interface IAuthenticationHandler
99
{
10-
void GetDescriptions(IDescribeSchemesContext context);
10+
void GetDescriptions(DescribeSchemesContext context);
1111

12-
void Authenticate(IAuthenticateContext context);
13-
Task AuthenticateAsync(IAuthenticateContext context);
12+
void Authenticate(AuthenticateContext context);
1413

15-
void Challenge(IChallengeContext context);
16-
void SignIn(ISignInContext context);
17-
void SignOut(ISignOutContext context);
14+
Task AuthenticateAsync(AuthenticateContext context);
15+
16+
void Challenge(ChallengeContext context);
17+
18+
void SignIn(SignInContext context);
19+
20+
void SignOut(SignOutContext context);
1821
}
1922
}

src/Microsoft.AspNet.Http.Interfaces/Authentication/IChallengeContext.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/Microsoft.AspNet.Http.Interfaces/Authentication/IDescribeSchemesContext.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/Microsoft.AspNet.Http.Interfaces/Authentication/ISignInContext.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/Microsoft.AspNet.Http.Interfaces/Authentication/ISignOutContext.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/Microsoft.AspNet.Http/Authentication/SignInContext.cs renamed to src/Microsoft.AspNet.Http.Interfaces/Authentication/SignInContext.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,26 @@
88

99
namespace Microsoft.AspNet.Http.Authentication
1010
{
11-
public class SignInContext : ISignInContext
11+
public class SignInContext
1212
{
13-
private bool _accepted;
14-
15-
public SignInContext([NotNull] string authenticationScheme, [NotNull] ClaimsPrincipal principal, IDictionary<string, string> dictionary)
13+
public SignInContext([NotNull] string authenticationScheme, [NotNull] ClaimsPrincipal principal, IDictionary<string, string> properties)
1614
{
1715
AuthenticationScheme = authenticationScheme;
1816
Principal = principal;
19-
Properties = dictionary ?? new Dictionary<string, string>(StringComparer.Ordinal);
17+
Properties = properties ?? new Dictionary<string, string>(StringComparer.Ordinal);
2018
}
2119

20+
public string AuthenticationScheme { get; }
21+
2222
public ClaimsPrincipal Principal { get; }
2323

2424
public IDictionary<string, string> Properties { get; }
2525

26-
public string AuthenticationScheme { get; }
27-
28-
public bool Accepted
29-
{
30-
get { return _accepted; }
31-
}
26+
public bool Accepted { get; private set; }
3227

33-
public void Accept(IDictionary<string, object> description)
28+
public void Accept()
3429
{
35-
_accepted = true;
30+
Accepted = true;
3631
}
3732
}
3833
}

src/Microsoft.AspNet.Http/Authentication/SignOutContext.cs renamed to src/Microsoft.AspNet.Http.Interfaces/Authentication/SignOutContext.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77

88
namespace Microsoft.AspNet.Http.Authentication
99
{
10-
public class SignOutContext : ISignOutContext
10+
public class SignOutContext
1111
{
12-
private bool _accepted;
13-
1412
public SignOutContext([NotNull] string authenticationScheme, IDictionary<string, string> properties)
1513
{
1614
AuthenticationScheme = authenticationScheme;
@@ -21,14 +19,11 @@ public SignOutContext([NotNull] string authenticationScheme, IDictionary<string,
2119

2220
public IDictionary<string, string> Properties { get; }
2321

24-
public bool Accepted
25-
{
26-
get { return _accepted; }
27-
}
22+
public bool Accepted { get; private set; }
2823

2924
public void Accept()
3025
{
31-
_accepted = true;
26+
Accepted = true;
3227
}
3328
}
34-
}
29+
}
Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
{
2-
"version": "1.0.0-*",
3-
"description": "ASP.NET 5 HTTP feature interface definitions.",
4-
"frameworks": {
5-
"dnx451": {},
6-
"dnxcore50": {
7-
"dependencies": {
8-
"System.Net.Primitives": "4.0.10-beta-*",
9-
"System.Net.WebSockets" : "4.0.0-beta-*",
10-
"System.Security.Claims": "4.0.0-beta-*",
11-
"System.Security.Cryptography.X509Certificates": "4.0.0-beta-*",
12-
"System.Security.Principal": "4.0.0-beta-*"
13-
}
2+
"version": "1.0.0-*",
3+
"description": "ASP.NET 5 HTTP feature interface definitions.",
4+
"dependencies": {
5+
"Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" }
6+
},
7+
"frameworks": {
8+
"dnx451": { },
9+
"dnxcore50": {
10+
"dependencies": {
11+
"System.Collections": "4.0.10-beta-*",
12+
"System.Net.Primitives": "4.0.10-beta-*",
13+
"System.Net.WebSockets": "4.0.0-beta-*",
14+
"System.Runtime.Extensions": "4.0.10-beta-*",
15+
"System.Security.Claims": "4.0.0-beta-*",
16+
"System.Security.Cryptography.X509Certificates": "4.0.0-beta-*",
17+
"System.Security.Principal": "4.0.0-beta-*"
18+
}
19+
}
1420
}
15-
}
1621
}

src/Microsoft.AspNet.Http/Authentication/AuthenticateContext.cs

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)