diff --git a/Octokit.Reactive/Clients/ObservableAuthorizationsClient.cs b/Octokit.Reactive/Clients/ObservableAuthorizationsClient.cs
index 20b6d1a3..062166e2 100644
--- a/Octokit.Reactive/Clients/ObservableAuthorizationsClient.cs
+++ b/Octokit.Reactive/Clients/ObservableAuthorizationsClient.cs
@@ -16,36 +16,60 @@ namespace Octokit.Reactive.Clients
_client = client;
}
+ ///
+ /// Get all s for the authenticated user. This method requires basic auth.
+ ///
+ ///
+ /// See API documentation for more
+ /// details.
+ ///
+ /// An
public IObservable> GetAll()
{
return _client.GetAll().ToObservable();
}
+ ///
+ /// Get a specific for the authenticated user. This method requires basic auth.
+ ///
+ ///
+ /// See API documentation for
+ /// more details.
+ ///
+ /// The id of the
+ /// An
public IObservable Get(int id)
{
return _client.Get(id).ToObservable();
}
+
///
/// This method will create a new authorization for the specified OAuth application, only if an authorization
/// for that application doesn’t already exist for the user. It returns the user’s token for the application
/// if one exists. Otherwise, it creates one.
///
- /// Client ID for the OAuth application that is requesting the token.
+ ///
+ /// See API
+ /// documentation for more details.
+ ///
+ /// Client ID for the OAuth application that is requesting the token
/// The client secret
- /// Definse the scopes and metadata for the token
+ /// Defines the scopes and metadata for the token
/// Thrown when the user does not have permission to make
/// this request. Check
+ /// Thrown when the current account has two-factor
+ /// authentication enabled.
///
public IObservable GetOrCreateApplicationAuthentication(
string clientId,
string clientSecret,
- AuthorizationUpdate authorization)
+ NewAuthorization newAuthorization)
{
Ensure.ArgumentNotNullOrEmptyString(clientId, "clientId");
Ensure.ArgumentNotNullOrEmptyString(clientSecret, "clientSecret");
- Ensure.ArgumentNotNull(authorization, "authorization");
+ Ensure.ArgumentNotNull(newAuthorization, "authorization");
- return _client.GetOrCreateApplicationAuthentication(clientId, clientSecret, authorization)
+ return _client.GetOrCreateApplicationAuthentication(clientId, clientSecret, newAuthorization)
.ToObservable();
}
@@ -54,45 +78,68 @@ namespace Octokit.Reactive.Clients
/// for that application doesn’t already exist for the user. It returns the user’s token for the application
/// if one exists. Otherwise, it creates one.
///
- /// Client ID for the OAuth application that is requesting the token.
+ ///
+ /// See API
+ /// documentation for more details.
+ ///
+ /// Client ID for the OAuth application that is requesting the token
/// The client secret
- /// Defines the scopes and metadata for the token
+ /// Defines the scopes and metadata for the token
///
/// Thrown when the user does not have permission to make
/// this request. Check
/// Thrown when the two-factor code is not
/// valid.
///
-
public IObservable GetOrCreateApplicationAuthentication(
string clientId,
string clientSecret,
- AuthorizationUpdate authorization,
+ NewAuthorization newAuthorization,
string twoFactorAuthenticationCode)
{
Ensure.ArgumentNotNullOrEmptyString(clientId, "clientId");
Ensure.ArgumentNotNullOrEmptyString(clientSecret, "clientSecret");
- Ensure.ArgumentNotNull(authorization, "authorization");
+ Ensure.ArgumentNotNull(newAuthorization, "authorization");
Ensure.ArgumentNotNullOrEmptyString(twoFactorAuthenticationCode, "twoFactorAuthenticationCode");
- return _client.GetOrCreateApplicationAuthentication(clientId, clientSecret, authorization, twoFactorAuthenticationCode)
+ return _client.GetOrCreateApplicationAuthentication(
+ clientId,
+ clientSecret,
+ newAuthorization,
+ twoFactorAuthenticationCode)
.ToObservable();
}
- public IObservable Update(int id, AuthorizationUpdate authorization)
+ ///
+ /// Create a new .
+ ///
+ /// Information about the new authorization to create
+ ///
+ public IObservable Create(NewAuthorization newAuthorization)
{
- Ensure.ArgumentNotNull(authorization, "authorization");
+ Ensure.ArgumentNotNull(newAuthorization, "authorization");
- return _client.Update(id, authorization).ToObservable();
+ return _client.Create(newAuthorization).ToObservable();
}
- public IObservable Create(AuthorizationUpdate authorization)
+ ///
+ /// Update the specified by the id.
+ ///
+ /// The id of the
+ /// The changes to make to the authorization
+ ///
+ public IObservable Update(int id, AuthorizationUpdate authorizationUpdate)
{
- Ensure.ArgumentNotNull(authorization, "authorization");
+ Ensure.ArgumentNotNull(authorizationUpdate, "authorizationUpdate");
- return _client.Create(authorization).ToObservable();
+ return _client.Update(id, authorizationUpdate).ToObservable();
}
+ ///
+ /// Deletes an .
+ ///
+ /// The systemwide id of the authorization
+ ///
public IObservable Delete(int id)
{
return _client.Delete(id).ToObservable();
diff --git a/Octokit.Reactive/Helpers/AuthorizationExtensions.cs b/Octokit.Reactive/Helpers/AuthorizationExtensions.cs
index 88bca520..645a9df0 100644
--- a/Octokit.Reactive/Helpers/AuthorizationExtensions.cs
+++ b/Octokit.Reactive/Helpers/AuthorizationExtensions.cs
@@ -6,31 +6,53 @@ namespace Octokit
{
public static class AuthorizationExtensions
{
+ ///
+ /// This method will create a new authorization for the specified OAuth application, only if an authorization
+ /// for that application doesn’t already exist for the user. It returns the user’s token for the application
+ /// if one exists. Otherwise, it creates a new one.
+ ///
+ ///
+ ///
+ /// This method allows the caller to provide a callback which is used to retrieve the two-factor code from
+ /// the user. Typically the callback is used to show some user interface to the user.
+ ///
+ ///
+ /// See API documentation
+ /// for more details.
+ ///
+ ///
+ /// The this method extends
+ /// Client ID for the OAuth application that is requesting the token
+ /// The client secret
+ /// Defines the scopes and metadata for the token
+ /// Callback used to retrieve the two-factor authentication code
+ /// from the user
+ ///
public static IObservable GetOrCreateApplicationAuthentication(
this IObservableAuthorizationsClient authorizationsClient,
string clientId,
string clientSecret,
- AuthorizationUpdate authorization,
+ NewAuthorization newAuthorization,
Func> twoFactorChallengeHandler
)
{
Ensure.ArgumentNotNull(authorizationsClient, "authorizationsClient");
Ensure.ArgumentNotNullOrEmptyString(clientId, "clientId");
Ensure.ArgumentNotNullOrEmptyString(clientSecret, "clientSecret");
- Ensure.ArgumentNotNull(authorization, "authorization");
+ Ensure.ArgumentNotNull(newAuthorization, "authorization");
- return authorizationsClient.GetOrCreateApplicationAuthentication(clientId, clientSecret, authorization)
+ return authorizationsClient.GetOrCreateApplicationAuthentication(clientId, clientSecret, newAuthorization)
.Catch(exception => twoFactorChallengeHandler(exception)
.SelectMany(result =>
result.ResendCodeRequested
? authorizationsClient.GetOrCreateApplicationAuthentication(
clientId,
clientSecret,
- authorization,
+ newAuthorization,
twoFactorChallengeHandler)
: authorizationsClient.GetOrCreateApplicationAuthentication(clientId,
clientSecret,
- authorization,
+ newAuthorization,
result.AuthenticationCode)));
}
}
diff --git a/Octokit.Reactive/IObservableAuthorizationsClient.cs b/Octokit.Reactive/IObservableAuthorizationsClient.cs
index 62c46acd..14d9159d 100644
--- a/Octokit.Reactive/IObservableAuthorizationsClient.cs
+++ b/Octokit.Reactive/IObservableAuthorizationsClient.cs
@@ -7,9 +7,27 @@ namespace Octokit.Reactive
{
public interface IObservableAuthorizationsClient
{
+ ///
+ /// Get all s for the authenticated user. This method requires basic auth.
+ ///
+ ///
+ /// See API documentation for more
+ /// details.
+ ///
+ /// An
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
Justification = "It's an API call, so it's not a property.")]
IObservable> GetAll();
+
+ ///
+ /// Get a specific for the authenticated user. This method requires basic auth.
+ ///
+ ///
+ /// See API documentation for
+ /// more details.
+ ///
+ /// The id of the
+ /// An
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get",
Justification = "It's fiiiine. It's fine. Trust us.")]
IObservable Get(int id);
@@ -19,9 +37,13 @@ namespace Octokit.Reactive
/// for that application doesn’t already exist for the user. It returns the user’s token for the application
/// if one exists. Otherwise, it creates one.
///
- /// Client ID for the OAuth application that is requesting the token.
+ ///
+ /// See API
+ /// documentation for more details.
+ ///
+ /// Client ID for the OAuth application that is requesting the token
/// The client secret
- /// Defines the scopes and metadata for the token
+ /// Defines the scopes and metadata for the token
/// Thrown when the user does not have permission to make
/// this request. Check
/// Thrown when the current account has two-factor
@@ -30,16 +52,20 @@ namespace Octokit.Reactive
IObservable GetOrCreateApplicationAuthentication(
string clientId,
string clientSecret,
- AuthorizationUpdate authorization);
+ NewAuthorization newAuthorization);
///
/// This method will create a new authorization for the specified OAuth application, only if an authorization
/// for that application doesn’t already exist for the user. It returns the user’s token for the application
/// if one exists. Otherwise, it creates one.
///
- /// Client ID for the OAuth application that is requesting the token.
+ ///
+ /// See API
+ /// documentation for more details.
+ ///
+ /// Client ID for the OAuth application that is requesting the token
/// The client secret
- /// Defines the scopes and metadata for the token
+ /// Defines the scopes and metadata for the token
///
/// Thrown when the user does not have permission to make
/// this request. Check
@@ -49,10 +75,29 @@ namespace Octokit.Reactive
IObservable GetOrCreateApplicationAuthentication(
string clientId,
string clientSecret,
- AuthorizationUpdate authorization,
+ NewAuthorization newAuthorization,
string twoFactorAuthenticationCode);
- IObservable Update(int id, AuthorizationUpdate authorization);
- IObservable Create(AuthorizationUpdate authorization);
+
+ ///
+ /// Create a new .
+ ///
+ /// Information about the new authorization to create
+ ///
+ IObservable Create(NewAuthorization newAuthorization);
+
+ ///
+ /// Update the specified by the id.
+ ///
+ /// The id of the
+ /// The changes to make to the authorization
+ ///
+ IObservable Update(int id, AuthorizationUpdate authorizationUpdate);
+
+ ///
+ /// Deletes an .
+ ///
+ /// The systemwide id of the authorization
+ ///
IObservable Delete(int id);
}
}
diff --git a/Octokit.Tests/Clients/AuthorizationsClientTests.cs b/Octokit.Tests/Clients/AuthorizationsClientTests.cs
index 7d014a1d..ba372b6b 100644
--- a/Octokit.Tests/Clients/AuthorizationsClientTests.cs
+++ b/Octokit.Tests/Clients/AuthorizationsClientTests.cs
@@ -73,10 +73,10 @@ namespace Octokit.Tests.Clients
var client = Substitute.For>();
var authEndpoint = new AuthorizationsClient(client);
- authEndpoint.Create(new AuthorizationUpdate());
+ authEndpoint.Create(new NewAuthorization());
client.Received().Create(Arg.Is(u => u.ToString() == "/authorizations")
- , Args.AuthorizationUpdate);
+ , Args.NewAuthorization);
}
}
@@ -99,7 +99,7 @@ namespace Octokit.Tests.Clients
[Fact]
public void GetsOrCreatesAuthenticationAtCorrectUrl()
{
- var data = new AuthorizationUpdate();
+ var data = new NewAuthorization();
var client = Substitute.For>();
var authEndpoint = new AuthorizationsClient(client);
@@ -112,7 +112,7 @@ namespace Octokit.Tests.Clients
[Fact]
public async Task WrapsTwoFactorFailureWithTwoFactorException()
{
- var data = new AuthorizationUpdate();
+ var data = new NewAuthorization();
var client = Substitute.For>();
client.GetOrCreate(Args.Uri, Args.Object, Args.String).Returns(_ => {throw new AuthorizationException();});
var authEndpoint = new AuthorizationsClient(client);
@@ -125,13 +125,13 @@ namespace Octokit.Tests.Clients
public async Task UsesCallbackToRetrieveTwoFactorCode()
{
var twoFactorChallengeResult = new TwoFactorChallengeResult("two-factor-code");
- var data = new AuthorizationUpdate { Note = "note" };
+ var data = new NewAuthorization { Note = "note" };
var client = Substitute.For();
- client.GetOrCreateApplicationAuthentication("clientId", "secret", Arg.Any())
+ client.GetOrCreateApplicationAuthentication("clientId", "secret", Arg.Any())
.Returns(_ => {throw new TwoFactorRequiredException();});
client.GetOrCreateApplicationAuthentication("clientId",
"secret",
- Arg.Any(),
+ Arg.Any(),
"two-factor-code")
.Returns(Task.Factory.StartNew(() => new Authorization {Token = "xyz"}));
@@ -142,10 +142,10 @@ namespace Octokit.Tests.Clients
client.Received().GetOrCreateApplicationAuthentication("clientId",
"secret",
- Arg.Is(u => u.Note == "note"));
+ Arg.Is(u => u.Note == "note"));
client.Received().GetOrCreateApplicationAuthentication("clientId",
"secret",
- Arg.Any(), "two-factor-code");
+ Arg.Any(), "two-factor-code");
Assert.Equal("xyz", result.Token);
}
@@ -157,13 +157,13 @@ namespace Octokit.Tests.Clients
TwoFactorChallengeResult.RequestResendCode,
new TwoFactorChallengeResult("two-factor-code")
});
- var data = new AuthorizationUpdate();
+ var data = new NewAuthorization();
var client = Substitute.For();
- client.GetOrCreateApplicationAuthentication("clientId", "secret", Arg.Any())
+ client.GetOrCreateApplicationAuthentication("clientId", "secret", Arg.Any())
.Returns(_ => { throw new TwoFactorRequiredException(); });
client.GetOrCreateApplicationAuthentication("clientId",
"secret",
- Arg.Any(),
+ Arg.Any(),
"two-factor-code")
.Returns(Task.Factory.StartNew(() => new Authorization { Token = "xyz" }));
@@ -174,12 +174,47 @@ namespace Octokit.Tests.Clients
client.Received().GetOrCreateApplicationAuthentication("clientId",
"secret",
- Arg.Any());
+ Arg.Any());
client.Received().GetOrCreateApplicationAuthentication("clientId",
"secret",
- Arg.Any(), "two-factor-code");
+ Arg.Any(), "two-factor-code");
Assert.Equal("xyz", result.Token);
}
+
+ [Fact]
+ public async Task CallsCallbackAgainWhenUserSubmitsBadCode()
+ {
+ var challengeResults = new Queue(new[]
+ {
+ TwoFactorChallengeResult.RequestResendCode,
+ new TwoFactorChallengeResult("wrong-code"),
+ });
+ var data = new NewAuthorization();
+ var client = Substitute.For();
+ client.GetOrCreateApplicationAuthentication("clientId", "secret", Arg.Any())
+ .Returns(_ => { throw new TwoFactorRequiredException(); });
+ client.GetOrCreateApplicationAuthentication("clientId",
+ "secret",
+ Arg.Any(),
+ "wrong-code")
+ .Returns(_ => { throw new TwoFactorChallengeFailedException(); });
+
+ var exception = AssertEx.Throws(async () =>
+ await client.GetOrCreateApplicationAuthentication(
+ "clientId",
+ "secret",
+ data,
+ e => Task.Factory.StartNew(() => challengeResults.Dequeue())));
+
+ Assert.NotNull(exception);
+ client.Received().GetOrCreateApplicationAuthentication("clientId",
+ "secret",
+ Arg.Any());
+ client.Received().GetOrCreateApplicationAuthentication("clientId",
+ "secret",
+ Arg.Any(),
+ "wrong-code");
+ }
}
}
}
diff --git a/Octokit.Tests/Helpers/Arg.cs b/Octokit.Tests/Helpers/Arg.cs
index 79b55a3a..184856f2 100644
--- a/Octokit.Tests/Helpers/Arg.cs
+++ b/Octokit.Tests/Helpers/Arg.cs
@@ -11,6 +11,11 @@ namespace Octokit.Tests
get { return Arg.Any(); }
}
+ public static NewAuthorization NewAuthorization
+ {
+ get { return Arg.Any(); }
+ }
+
public static Uri Uri
{
get { return Arg.Any(); }
diff --git a/Octokit/Clients/AuthorizationsClient.cs b/Octokit/Clients/AuthorizationsClient.cs
index 019933e3..7eaba20f 100644
--- a/Octokit/Clients/AuthorizationsClient.cs
+++ b/Octokit/Clients/AuthorizationsClient.cs
@@ -2,15 +2,19 @@
#if NET_45
using System.Collections.Generic;
#endif
-using System.Collections;
using System.Threading.Tasks;
-using Octokit.Internal;
namespace Octokit
{
+ ///
+ /// Client for the OAuth2 API.
+ ///
+ ///
+ /// See OAuth API documentation for more details.
+ ///
public class AuthorizationsClient : ApiClient, IAuthorizationsClient
{
- static readonly Uri authorizationsEndpoint = new Uri("/authorizations", UriKind.Relative);
+ static readonly Uri _authorizationsEndpoint = new Uri("/authorizations", UriKind.Relative);
public AuthorizationsClient(IApiConnection client) : base(client)
{
@@ -19,16 +23,24 @@ namespace Octokit
///
/// Get all s for the authenticated user. This method requires basic auth.
///
+ ///
+ /// See API documentation for more
+ /// details.
+ ///
/// An
public async Task> GetAll()
{
- return await Client.GetAll(authorizationsEndpoint);
+ return await Client.GetAll(_authorizationsEndpoint);
}
///
/// Get a specific for the authenticated user. This method requires basic auth.
///
- /// The id of the .
+ ///
+ /// See API documentation for
+ /// more details.
+ ///
+ /// The id of the
/// An
public async Task Get(int id)
{
@@ -41,49 +53,75 @@ namespace Octokit
/// for that application doesn’t already exist for the user. It returns the user’s token for the application
/// if one exists. Otherwise, it creates one.
///
- /// Client ID for the OAuth application that is requesting the token.
+ ///
+ /// See API
+ /// documentation for more details.
+ ///
+ /// Client ID for the OAuth application that is requesting the token
/// The client secret
- /// Definse the scopes and metadata for the token
+ /// Defines the scopes and metadata for the token
+ /// Thrown when the user does not have permission to make
+ /// this request. Check
+ /// Thrown when the current account has two-factor
+ /// authentication enabled.
///
public async Task GetOrCreateApplicationAuthentication(
string clientId,
string clientSecret,
- AuthorizationUpdate authorization)
+ NewAuthorization newAuthorization)
{
Ensure.ArgumentNotNullOrEmptyString(clientId, "clientId");
Ensure.ArgumentNotNullOrEmptyString(clientSecret, "clientSecret");
- Ensure.ArgumentNotNull(authorization, "authorization");
+ Ensure.ArgumentNotNull(newAuthorization, "authorization");
var endpoint = "/authorizations/clients/{0}".FormatUri(clientId);
var requestData = new
{
client_secret = clientSecret,
- scopes = authorization.Scopes,
- note = authorization.Note,
- note_url = authorization.NoteUrl
+ scopes = newAuthorization.Scopes,
+ note = newAuthorization.Note,
+ note_url = newAuthorization.NoteUrl
};
return await Client.GetOrCreate(endpoint, requestData);
}
+ ///
+ /// This method will create a new authorization for the specified OAuth application, only if an authorization
+ /// for that application doesn’t already exist for the user. It returns the user’s token for the application
+ /// if one exists. Otherwise, it creates one.
+ ///
+ ///
+ /// See API
+ /// documentation for more details.
+ ///
+ /// Client ID for the OAuth application that is requesting the token
+ /// The client secret
+ /// Defines the scopes and metadata for the token
+ ///
+ /// Thrown when the user does not have permission to make
+ /// this request. Check
+ /// Thrown when the two-factor code is not
+ /// valid.
+ ///
public async Task GetOrCreateApplicationAuthentication(
string clientId,
string clientSecret,
- AuthorizationUpdate authorization,
+ NewAuthorization newAuthorization,
string twoFactorAuthenticationCode)
{
Ensure.ArgumentNotNullOrEmptyString(clientId, "clientId");
Ensure.ArgumentNotNullOrEmptyString(clientSecret, "clientSecret");
- Ensure.ArgumentNotNull(authorization, "authorization");
+ Ensure.ArgumentNotNull(newAuthorization, "authorization");
Ensure.ArgumentNotNullOrEmptyString(twoFactorAuthenticationCode, "twoFactorAuthenticationCode");
var endpoint = "/authorizations/clients/{0}".FormatUri(clientId);
var requestData = new
{
client_secret = clientSecret,
- scopes = authorization.Scopes,
- note = authorization.Note,
- note_url = authorization.NoteUrl
+ scopes = newAuthorization.Scopes,
+ note = newAuthorization.Note,
+ note_url = newAuthorization.NoteUrl
};
try
@@ -102,27 +140,27 @@ namespace Octokit
///
/// Update the specified .
///
- /// The id of the .
- ///
+ /// The id of the
+ /// The changes to make to the authorization
///
- public async Task Update(int id, AuthorizationUpdate authorization)
+ public async Task Update(int id, AuthorizationUpdate authorizationUpdate)
{
- Ensure.ArgumentNotNull(authorization, "authorization");
+ Ensure.ArgumentNotNull(authorizationUpdate, "authorizationUpdate");
var endpoint = "/authorizations/{0}".FormatUri(id);
- return await Client.Update(endpoint, authorization);
+ return await Client.Update(endpoint, authorizationUpdate);
}
///
/// Create a new .
///
- ///
+ ///
///
- public async Task Create(AuthorizationUpdate authorization)
+ public async Task Create(NewAuthorization newAuthorization)
{
- Ensure.ArgumentNotNull(authorization, "authorization");
+ Ensure.ArgumentNotNull(newAuthorization, "newAuthorization");
- return await Client.Create(authorizationsEndpoint, authorization);
+ return await Client.Create(_authorizationsEndpoint, newAuthorization);
}
///
diff --git a/Octokit/Exceptions/AuthorizationException.cs b/Octokit/Exceptions/AuthorizationException.cs
index 910435e0..b9888102 100644
--- a/Octokit/Exceptions/AuthorizationException.cs
+++ b/Octokit/Exceptions/AuthorizationException.cs
@@ -33,43 +33,4 @@ 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();
- }
- }
-*/
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/Octokit/Helpers/AuthorizationExtensions.cs b/Octokit/Helpers/AuthorizationExtensions.cs
index 191b4a4e..895ae92c 100644
--- a/Octokit/Helpers/AuthorizationExtensions.cs
+++ b/Octokit/Helpers/AuthorizationExtensions.cs
@@ -5,19 +5,40 @@ namespace Octokit
{
public static class AuthorizationExtensions
{
+ ///
+ /// This method will create a new authorization for the specified OAuth application, only if an authorization
+ /// for that application doesn’t already exist for the user. It returns the user’s token for the application
+ /// if one exists. Otherwise, it creates a new one.
+ ///
+ ///
+ ///
+ /// This method allows the caller to provide a callback which is used to retrieve the two-factor code from
+ /// the user. Typically the callback is used to show some user interface to the user.
+ ///
+ ///
+ /// See API documentation
+ /// for more details.
+ ///
+ ///
+ /// The this method extends
+ /// Client ID for the OAuth application that is requesting the token
+ /// The client secret
+ /// Defines the scopes and metadata for the token
+ /// Callback used to retrieve the two-factor authentication code
+ /// from the user
+ ///
public static async Task GetOrCreateApplicationAuthentication(
this IAuthorizationsClient authorizationsClient,
string clientId,
string clientSecret,
- AuthorizationUpdate authorization,
+ NewAuthorization newAuthorization,
Func> twoFactorChallengeHandler
)
{
TwoFactorRequiredException twoFactorException = null;
try
{
- return await authorizationsClient.GetOrCreateApplicationAuthentication(clientId, clientSecret, authorization);
-
+ return await authorizationsClient.GetOrCreateApplicationAuthentication(clientId, clientSecret, newAuthorization);
}
catch (TwoFactorRequiredException exception)
{
@@ -29,13 +50,13 @@ namespace Octokit
? authorizationsClient.GetOrCreateApplicationAuthentication(
clientId,
clientSecret,
- authorization,
+ newAuthorization,
twoFactorChallengeHandler)
- : authorizationsClient.GetOrCreateApplicationAuthentication(clientId,
+ : authorizationsClient.GetOrCreateApplicationAuthentication(
+ clientId,
clientSecret,
- authorization,
+ newAuthorization,
twoFactorChallengeResult.AuthenticationCode));
-
}
}
}
diff --git a/Octokit/IAuthorizationsClient.cs b/Octokit/IAuthorizationsClient.cs
index 3af84c7a..648e785f 100644
--- a/Octokit/IAuthorizationsClient.cs
+++ b/Octokit/IAuthorizationsClient.cs
@@ -4,27 +4,51 @@ using System.Threading.Tasks;
namespace Octokit
{
+ ///
+ /// Interface for the client of the OAuth2 API.
+ ///
+ ///
+ /// See OAuth API documentation for more details.
+ ///
public interface IAuthorizationsClient
{
+ ///
+ /// Get all s for the authenticated user. This method requires basic auth.
+ ///
+ ///
+ /// See API documentation for more
+ /// details.
+ ///
+ /// An
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
Justification = "It's an API call, so it's not a property.")]
Task> GetAll();
+
///
/// Get a specific for the authenticated user. This method requires basic auth.
///
- /// The id of the .
+ ///
+ /// See API documentation for
+ /// more details.
+ ///
+ /// The id of the
/// An
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get",
Justification = "It's fiiiine. It's fine. Trust us.")]
Task Get(int id);
+
///
/// This method will create a new authorization for the specified OAuth application, only if an authorization
/// for that application doesn’t already exist for the user. It returns the user’s token for the application
/// if one exists. Otherwise, it creates one.
///
- /// Client ID for the OAuth application that is requesting the token.
+ ///
+ /// See API
+ /// documentation for more details.
+ ///
+ /// Client ID for the OAuth application that is requesting the token
/// The client secret
- /// Defines the scopes and metadata for the token
+ /// Defines the scopes and metadata for the token
/// Thrown when the user does not have permission to make
/// this request. Check
/// Thrown when the current account has two-factor
@@ -33,15 +57,20 @@ namespace Octokit
Task GetOrCreateApplicationAuthentication(
string clientId,
string clientSecret,
- AuthorizationUpdate authorization);
+ NewAuthorization newAuthorization);
+
///
/// This method will create a new authorization for the specified OAuth application, only if an authorization
/// for that application doesn’t already exist for the user. It returns the user’s token for the application
/// if one exists. Otherwise, it creates one.
///
- /// Client ID for the OAuth application that is requesting the token.
+ ///
+ /// See API
+ /// documentation for more details.
+ ///
+ /// Client ID for the OAuth application that is requesting the token
/// The client secret
- /// Defines the scopes and metadata for the token
+ /// Defines the scopes and metadata for the token
///
/// Thrown when the user does not have permission to make
/// this request. Check
@@ -51,10 +80,29 @@ namespace Octokit
Task GetOrCreateApplicationAuthentication(
string clientId,
string clientSecret,
- AuthorizationUpdate authorization,
+ NewAuthorization newAuthorization,
string twoFactorAuthenticationCode);
- Task Update(int id, AuthorizationUpdate authorization);
- Task Create(AuthorizationUpdate authorization);
+
+ ///
+ /// Create a new .
+ ///
+ /// Information about the new authorization to create
+ ///
+ Task Create(NewAuthorization newAuthorization);
+
+ ///
+ /// Update the specified by the id.
+ ///
+ /// The id of the
+ /// The changes to make to the authorization
+ ///
+ Task Update(int id, AuthorizationUpdate authorizationUpdate);
+
+ ///
+ /// Deletes an .
+ ///
+ /// The systemwide id of the authorization
+ ///
Task Delete(int id);
}
}
diff --git a/Octokit/Models/AuthorizationUpdate.cs b/Octokit/Models/AuthorizationUpdate.cs
index 1c0732fc..6b14205a 100644
--- a/Octokit/Models/AuthorizationUpdate.cs
+++ b/Octokit/Models/AuthorizationUpdate.cs
@@ -1,22 +1,34 @@
-using System.Diagnostics.CodeAnalysis;
+using System.Collections.Generic;
namespace Octokit
{
+ ///
+ /// Used to create a new authorization.
+ ///
public class AuthorizationUpdate
{
///
- /// Replace scopes with this list.
+ /// Replaces the authorization scopes with this list.
///
- [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "Special type of model object that only updates none-null fields.")]
- public string[] Scopes { get; set; }
+ public IEnumerable Scopes { get; set; }
///
- /// Notes about this particular .
+ /// A list of scopes to add to this authorization.
+ ///
+ public IEnumerable AddScopes { get; set; }
+
+ ///
+ /// A list of scopes to remove from this authorization.
+ ///
+ public IEnumerable RemoveScopes { get; set; }
+
+ ///
+ /// An optional note to remind you what the OAuth token is for.
///
public string Note { get; set; }
///
- /// A url for more information about notes.
+ // An optional URL to remind you what app the OAuth token is for.
///
public string NoteUrl { get; set; }
}
diff --git a/Octokit/Models/NewAuthorization.cs b/Octokit/Models/NewAuthorization.cs
new file mode 100644
index 00000000..19a48e49
--- /dev/null
+++ b/Octokit/Models/NewAuthorization.cs
@@ -0,0 +1,25 @@
+using System.Collections.Generic;
+
+namespace Octokit
+{
+ ///
+ /// Used to create a new authorization.
+ ///
+ public class NewAuthorization
+ {
+ ///
+ /// Replaces the authorization scopes with this list.
+ ///
+ public IEnumerable Scopes { get; set; }
+
+ ///
+ /// An optional note to remind you what the OAuth token is for.
+ ///
+ public string Note { get; set; }
+
+ ///
+ // An optional URL to remind you what app the OAuth token is for.
+ ///
+ public string NoteUrl { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj
index 95c0a5d8..7488fd9d 100644
--- a/Octokit/Octokit.csproj
+++ b/Octokit/Octokit.csproj
@@ -151,6 +151,7 @@
+
diff --git a/Octokit/OctokitRT.csproj b/Octokit/OctokitRT.csproj
index 2f4bfa7a..c10df672 100644
--- a/Octokit/OctokitRT.csproj
+++ b/Octokit/OctokitRT.csproj
@@ -170,6 +170,7 @@
+