Implement GetOrCreateApplicationAuthentication

Implements the endpoint for creating an application authorization token.
This commit is contained in:
Haacked
2013-10-09 16:28:59 -07:00
parent 9d71d406fa
commit 33ad79c0fe
19 changed files with 653 additions and 4 deletions
@@ -34,3 +34,42 @@ namespace Octokit
#endif
}
}
/*
[Fact]
public void CreatesGitHubErrorFromJsonResponse()
{
var exception = new ApiUnauthorizedWebException("{\"message\":\"Bad credentials.\"}");
exception.ApiUnauthorizedError.Message.ShouldEqual("Bad credentials.");
exception.ApiUnauthorizedError.Errors.ShouldBeNull();
}
[Theory]
[InlineData("")]
[InlineData(null)]
[InlineData("{{{{{")]
public void CreatesGitHubErrorIfResponseMessageIsNotValidJson(string responseContent)
{
var exception = new ApiUnauthorizedWebException(responseContent);
exception.ApiUnauthorizedError.Message.ShouldEqual(responseContent);
Assert.False(exception.RequiresSecondFactor);
}
[Fact]
public void CanPopulateObjectFromSerializedData()
{
var exception = new ApiUnauthorizedWebException("{message:\"Bad credentials.\"}");
using (var stream = new MemoryStream())
{
var formatter = new BinaryFormatter();
formatter.Serialize(stream, exception);
stream.Position = 0;
var deserialized = (ApiUnauthorizedWebException)formatter.Deserialize(stream);
deserialized.ApiUnauthorizedError.Message.ShouldEqual("Bad credentials.");
exception.ApiUnauthorizedError.Errors.ShouldBeNull();
}
}
*/
@@ -0,0 +1,31 @@
using System;
using System.Runtime.Serialization;
namespace Octokit
{
#if !NETFX_CORE
[Serializable]
#endif
public class TwoFactorChallengeFailedException : AuthorizationException
{
public TwoFactorChallengeFailedException()
{
}
public TwoFactorChallengeFailedException(string message) : base(message)
{
}
public TwoFactorChallengeFailedException(string message, Exception innerException)
: base(message, innerException)
{
}
#if !NETFX_CORE
protected TwoFactorChallengeFailedException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
#endif
}
}
@@ -0,0 +1,55 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;
namespace Octokit
{
#if !NETFX_CORE
[Serializable]
#endif
public class TwoFactorRequiredException : AuthorizationException
{
public TwoFactorRequiredException()
{
}
public TwoFactorRequiredException(string message) : base(message)
{
}
public TwoFactorRequiredException(string message, Exception innerException) : base(message, innerException)
{
}
public TwoFactorRequiredException(string message, TwoFactorType twoFactorType)
: base(message)
{
TwoFactorType = twoFactorType;
}
#if !NETFX_CORE
protected TwoFactorRequiredException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
if (info == null) return;
TwoFactorType = (TwoFactorType) (info.GetInt32("TwoFactorType"));
}
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("TwoFactorType", TwoFactorType);
}
#endif
public TwoFactorType TwoFactorType { get; private set; }
}
public enum TwoFactorType
{
None,
Unknown,
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Sms")] Sms,
AuthenticatorApp
}
}