mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-04 19:26:51 +00:00
Implement GetOrCreateApplicationAuthentication
Implements the endpoint for creating an application authorization token.
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user