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

Commit 20fdbe2

Browse files
committed
Responding to comments and removing null check for CookieToken
1 parent c143153 commit 20fdbe2

File tree

4 files changed

+14
-24
lines changed

4 files changed

+14
-24
lines changed

src/Microsoft.AspNet.Mvc.Core/AntiForgery/AntiForgery.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public HtmlString GetHtml([NotNull] HttpContext context)
5353
/// <param name="oldCookieToken">The anti-forgery token - if any - that already existed
5454
/// for this request. May be null. The anti-forgery system will try to reuse this cookie
5555
/// value when generating a matching form token.</param>
56+
/// <remarks>
57+
/// Unlike the GetHtml(HttpContext context) method, this method has no side effect. The caller
58+
/// is responsible for setting the response cookie and injecting the returned
59+
/// form token as appropriate.
5660
/// </remarks>
5761
public AntiForgeryTokenSet GetTokens([NotNull] HttpContext context, string oldCookieToken)
5862
{
@@ -66,7 +70,7 @@ public AntiForgeryTokenSet GetTokens([NotNull] HttpContext context, string oldCo
6670

6771
/// <summary>
6872
/// Validates an anti-forgery token that was supplied for this request.
69-
/// The anti-forgery token may be generated by calling GetHtml().
73+
/// The anti-forgery token may be generated by calling GetHtml(HttpContext context).
7074
/// </summary>
7175
/// <param name="context">The HTTP context associated with the current call.</param>
7276
public async Task ValidateAsync([NotNull] HttpContext context)

src/Microsoft.AspNet.Mvc.Core/AntiForgery/AntiForgeryToken.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@ internal sealed class AntiForgeryToken
77
internal const int SecurityTokenBitLength = 128;
88
internal const int ClaimUidBitLength = 256;
99

10-
private string _additionalData;
10+
private string _additionalData = string.Empty;
11+
private string _username = string.Empty;
1112
private BinaryBlob _securityToken;
12-
private string _username;
1313

1414
public string AdditionalData
1515
{
16-
get
17-
{
18-
return _additionalData ?? String.Empty;
19-
}
16+
get { return _additionalData; }
2017
set
2118
{
22-
_additionalData = value;
19+
_additionalData = value ?? string.Empty;
2320
}
2421
}
2522

@@ -45,13 +42,10 @@ public BinaryBlob SecurityToken
4542

4643
public string Username
4744
{
48-
get
49-
{
50-
return _username ?? String.Empty;
51-
}
45+
get { return _username; }
5246
set
5347
{
54-
_username = value;
48+
_username = value ?? string.Empty;
5549
}
5650
}
5751
}

src/Microsoft.AspNet.Mvc.Core/AntiForgery/AntiForgeryTokenSerializer.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ public AntiForgeryToken Deserialize(string serializedToken)
3838
// swallow all exceptions - homogenize error if something went wrong
3939
}
4040

41-
// TODO: Return proper exception here.
4241
// if we reached this point, something went wrong deserializing
43-
// throw HttpAntiForgeryException.CreateDeserializationFailedException();
4442
throw new InvalidOperationException(Resources.AntiForgeryToken_DeserializationFailed);
4543
}
4644

@@ -128,8 +126,6 @@ public string Serialize([NotNull] AntiForgeryToken token)
128126
}
129127
}
130128

131-
// TODO: This is temporary replacement for HttpServerUtility.UrlTokenEncode.
132-
// This will be removed when webutils has this.
133129
private string UrlTokenEncode(byte[] input)
134130
{
135131
var base64String = Convert.ToBase64String(input);
@@ -161,8 +157,6 @@ private string UrlTokenEncode(byte[] input)
161157
return sb.ToString();
162158
}
163159

164-
// TODO: This is temporary replacement for HttpServerUtility.UrlTokenDecode.
165-
// This will be removed when webutils has this.
166160
private byte[] UrlTokenDecode(string input)
167161
{
168162
var sb = new StringBuilder();

src/Microsoft.AspNet.Mvc.Core/AntiForgery/AntiForgeryTokenSet.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,15 @@ public AntiForgeryTokenSet(string formToken, string cookieToken)
1212
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, formToken);
1313
}
1414

15-
if (string.IsNullOrEmpty(cookieToken))
16-
{
17-
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, cookieToken);
18-
}
19-
2015
FormToken = formToken;
2116
CookieToken = cookieToken;
2217
}
2318

2419
public string FormToken { get; private set; }
2520

21+
// The cookie token is allowed to be null.
22+
// This would be the case when the old cookie token is still valid.
23+
// In such cases a call to GetTokens would return a token set with null cookie token.
2624
public string CookieToken { get; private set; }
2725
}
2826
}

0 commit comments

Comments
 (0)