Updated for the TwitterOptions Validation for the ConsumerKey and Con… (#1337)
This commit is contained in:
parent
0c82d94a54
commit
43db99a568
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Security.Claims;
|
||||
using System.Globalization;
|
||||
using Microsoft.AspNetCore.Authentication.OAuth.Claims;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
|
|
@ -86,6 +87,23 @@ namespace Microsoft.AspNetCore.Authentication.Twitter
|
|||
set => _stateCookieBuilder = value ?? throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Added the validate method to ensure that the customer key and customer secret values are not not empty for the twitter authentication middleware
|
||||
/// </summary>
|
||||
public override void Validate()
|
||||
{
|
||||
base.Validate();
|
||||
if (string.IsNullOrEmpty(ConsumerKey))
|
||||
{
|
||||
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, nameof(ConsumerKey)), nameof(ConsumerKey));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(ConsumerSecret))
|
||||
{
|
||||
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, nameof(ConsumerSecret)), nameof(ConsumerSecret));
|
||||
}
|
||||
}
|
||||
|
||||
private class TwitterCookieBuilder : CookieBuilder
|
||||
{
|
||||
private readonly TwitterOptions _twitterOptions;
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.Authentication.Twitter
|
|||
}
|
||||
};
|
||||
},
|
||||
context =>
|
||||
context =>
|
||||
{
|
||||
// REVIEW: Gross
|
||||
context.ChallengeAsync("Twitter").GetAwaiter().GetResult();
|
||||
|
|
@ -75,6 +75,36 @@ namespace Microsoft.AspNetCore.Authentication.Twitter
|
|||
Assert.Contains("custom=test", query);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the Twitter Options to check if the Consumer Key is missing in the TwitterOptions and if so throws the ArgumentException
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Fact]
|
||||
public async Task ThrowsIfClientIdMissing()
|
||||
{
|
||||
var server = CreateServer(o =>
|
||||
{
|
||||
o.ConsumerSecret = "Test Consumer Secret";
|
||||
});
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>("ConsumerKey", async () => await server.SendAsync("http://example.com/challenge"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the Twitter Options to check if the Consumer Secret is missing in the TwitterOptions and if so throws the ArgumentException
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Fact]
|
||||
public async Task ThrowsIfClientSecretMissing()
|
||||
{
|
||||
var server = CreateServer(o =>
|
||||
{
|
||||
o.ConsumerKey = "Test Consumer Key";
|
||||
});
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>("ConsumerSecret", async () => await server.SendAsync("http://example.com/challenge"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BadSignInWillThrow()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue