mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-04 11:24:44 +00:00
Implement Authorization Create method
This commit is contained in:
@@ -31,6 +31,56 @@ namespace Octokit.Reactive
|
||||
Justification = "It's fiiiine. It's fine. Trust us.")]
|
||||
IObservable<Authorization> Get(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new authorization for the specified OAuth application if an authorization for that application
|
||||
/// doesn’t already exist for the user; otherwise, it fails.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method requires authentication.
|
||||
/// See the <a href="http://developer.github.com/v3/oauth/#get-or-create-an-authorization-for-a-specific-app">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="clientId">Client ID of the OAuth application for the token</param>
|
||||
/// <param name="clientSecret">The client secret</param>
|
||||
/// <param name="newAuthorization">Describes the new authorization to create</param>
|
||||
/// <exception cref="AuthorizationException">
|
||||
/// Thrown when the current user does not have permission to make this request.
|
||||
/// </exception>
|
||||
/// <exception cref="TwoFactorRequiredException">
|
||||
/// Thrown when the current account has two-factor authentication enabled and an authentication code is required.
|
||||
/// </exception>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns>The created <see cref="Authorization"/>.</returns>
|
||||
IObservable<ApplicationAuthorization> Create(
|
||||
string clientId,
|
||||
string clientSecret,
|
||||
NewAuthorization newAuthorization);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new authorization for the specified OAuth application if an authorization for that application
|
||||
/// doesn’t already exist for the user; otherwise, it fails.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method requires authentication.
|
||||
/// See the <a href="http://developer.github.com/v3/oauth/#get-or-create-an-authorization-for-a-specific-app">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="clientId">Client ID of the OAuth application for the token</param>
|
||||
/// <param name="clientSecret">The client secret</param>
|
||||
/// <param name="twoFactorAuthenticationCode">The two-factor authentication code in response to the current user's previous challenge</param>
|
||||
/// <param name="newAuthorization">Describes the new authorization to create</param>
|
||||
/// <exception cref="AuthorizationException">
|
||||
/// Thrown when the current user does not have permission to make this request.
|
||||
/// </exception>
|
||||
/// <exception cref="TwoFactorRequiredException">
|
||||
/// Thrown when the current account has two-factor authentication enabled and an authentication code is required.
|
||||
/// </exception>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns>The created <see cref="Authorization"/>.</returns>
|
||||
IObservable<ApplicationAuthorization> Create(
|
||||
string clientId,
|
||||
string clientSecret,
|
||||
NewAuthorization newAuthorization,
|
||||
string twoFactorAuthenticationCode);
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
|
||||
@@ -45,6 +45,71 @@ namespace Octokit.Reactive
|
||||
return _client.Get(id).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new authorization for the specified OAuth application if an authorization for that application
|
||||
/// doesn’t already exist for the user; otherwise, it fails.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method requires authentication.
|
||||
/// See the <a href="http://developer.github.com/v3/oauth/#get-or-create-an-authorization-for-a-specific-app">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="clientId">Client ID of the OAuth application for the token</param>
|
||||
/// <param name="clientSecret">The client secret</param>
|
||||
/// <param name="newAuthorization">Describes the new authorization to create</param>
|
||||
/// <exception cref="AuthorizationException">
|
||||
/// Thrown when the current user does not have permission to make this request.
|
||||
/// </exception>
|
||||
/// <exception cref="TwoFactorRequiredException">
|
||||
/// Thrown when the current account has two-factor authentication enabled and an authentication code is required.
|
||||
/// </exception>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns>The created <see cref="Authorization"/>.</returns>
|
||||
public IObservable<ApplicationAuthorization> Create(
|
||||
string clientId,
|
||||
string clientSecret,
|
||||
NewAuthorization newAuthorization)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(clientId, "clientId");
|
||||
Ensure.ArgumentNotNullOrEmptyString(clientSecret, "clientSecret");
|
||||
Ensure.ArgumentNotNull(newAuthorization, "authorization");
|
||||
|
||||
return _client.Create(clientId, clientSecret, newAuthorization).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new authorization for the specified OAuth application if an authorization for that application
|
||||
/// doesn’t already exist for the user; otherwise, it fails.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method requires authentication.
|
||||
/// See the <a href="http://developer.github.com/v3/oauth/#get-or-create-an-authorization-for-a-specific-app">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="clientId">Client ID of the OAuth application for the token</param>
|
||||
/// <param name="clientSecret">The client secret</param>
|
||||
/// <param name="twoFactorAuthenticationCode">The two-factor authentication code in response to the current user's previous challenge</param>
|
||||
/// <param name="newAuthorization">Describes the new authorization to create</param>
|
||||
/// <exception cref="AuthorizationException">
|
||||
/// Thrown when the current user does not have permission to make this request.
|
||||
/// </exception>
|
||||
/// <exception cref="TwoFactorRequiredException">
|
||||
/// Thrown when the current account has two-factor authentication enabled and an authentication code is required.
|
||||
/// </exception>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns>The created <see cref="Authorization"/>.</returns>
|
||||
public IObservable<ApplicationAuthorization> Create(
|
||||
string clientId,
|
||||
string clientSecret,
|
||||
NewAuthorization newAuthorization,
|
||||
string twoFactorAuthenticationCode)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(clientId, "clientId");
|
||||
Ensure.ArgumentNotNullOrEmptyString(clientSecret, "clientSecret");
|
||||
Ensure.ArgumentNotNull(newAuthorization, "authorization");
|
||||
Ensure.ArgumentNotNullOrEmptyString(twoFactorAuthenticationCode, "twoFactorAuthenticationCode");
|
||||
|
||||
return _client.Create(clientId, clientSecret, newAuthorization).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
|
||||
@@ -57,6 +57,95 @@ namespace Octokit
|
||||
return ApiConnection.Get<Authorization>(ApiUrls.Authorizations(id), null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new authorization for the specified OAuth application if an authorization for that application
|
||||
/// doesn’t already exist for the user; otherwise, it fails.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method requires authentication.
|
||||
/// See the <a href="http://developer.github.com/v3/oauth/#get-or-create-an-authorization-for-a-specific-app">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="clientId">Client ID of the OAuth application for the token</param>
|
||||
/// <param name="clientSecret">The client secret</param>
|
||||
/// <param name="newAuthorization">Describes the new authorization to create</param>
|
||||
/// <exception cref="AuthorizationException">
|
||||
/// Thrown when the current user does not have permission to make this request.
|
||||
/// </exception>
|
||||
/// <exception cref="TwoFactorRequiredException">
|
||||
/// Thrown when the current account has two-factor authentication enabled and an authentication code is required.
|
||||
/// </exception>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns>The created <see cref="Authorization"/>.</returns>
|
||||
public Task<ApplicationAuthorization> Create(
|
||||
string clientId,
|
||||
string clientSecret,
|
||||
NewAuthorization newAuthorization)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(clientId, "clientId");
|
||||
Ensure.ArgumentNotNullOrEmptyString(clientSecret, "clientSecret");
|
||||
Ensure.ArgumentNotNull(newAuthorization, "authorization");
|
||||
|
||||
var requestData = new
|
||||
{
|
||||
client_id = clientId,
|
||||
client_secret = clientSecret,
|
||||
scopes = newAuthorization.Scopes,
|
||||
note = newAuthorization.Note,
|
||||
note_url = newAuthorization.NoteUrl,
|
||||
fingerprint = newAuthorization.Fingerprint
|
||||
};
|
||||
|
||||
var endpoint = ApiUrls.Authorizations();
|
||||
|
||||
return ApiConnection.Put<ApplicationAuthorization>(endpoint, requestData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new authorization for the specified OAuth application if an authorization for that application
|
||||
/// doesn’t already exist for the user; otherwise, it fails.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method requires authentication.
|
||||
/// See the <a href="http://developer.github.com/v3/oauth/#get-or-create-an-authorization-for-a-specific-app">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="clientId">Client ID of the OAuth application for the token</param>
|
||||
/// <param name="clientSecret">The client secret</param>
|
||||
/// <param name="twoFactorAuthenticationCode">The two-factor authentication code in response to the current user's previous challenge</param>
|
||||
/// <param name="newAuthorization">Describes the new authorization to create</param>
|
||||
/// <exception cref="AuthorizationException">
|
||||
/// Thrown when the current user does not have permission to make this request.
|
||||
/// </exception>
|
||||
/// <exception cref="TwoFactorRequiredException">
|
||||
/// Thrown when the current account has two-factor authentication enabled and an authentication code is required.
|
||||
/// </exception>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns>The created <see cref="Authorization"/>.</returns>
|
||||
public Task<ApplicationAuthorization> Create(
|
||||
string clientId,
|
||||
string clientSecret,
|
||||
NewAuthorization newAuthorization,
|
||||
string twoFactorAuthenticationCode)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(clientId, "clientId");
|
||||
Ensure.ArgumentNotNullOrEmptyString(clientSecret, "clientSecret");
|
||||
Ensure.ArgumentNotNull(newAuthorization, "authorization");
|
||||
Ensure.ArgumentNotNullOrEmptyString(twoFactorAuthenticationCode, "twoFactorAuthenticationCode");
|
||||
|
||||
var requestData = new
|
||||
{
|
||||
client_id = clientId,
|
||||
client_secret = clientSecret,
|
||||
scopes = newAuthorization.Scopes,
|
||||
note = newAuthorization.Note,
|
||||
note_url = newAuthorization.NoteUrl,
|
||||
fingerprint = newAuthorization.Fingerprint
|
||||
};
|
||||
|
||||
var endpoint = ApiUrls.Authorizations();
|
||||
|
||||
return ApiConnection.Put<ApplicationAuthorization>(endpoint, requestData, twoFactorAuthenticationCode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new authorization for the specified OAuth application if an authorization for that application doesn’t already
|
||||
/// exist for the user; otherwise, returns the user’s existing authorization for that application.
|
||||
|
||||
@@ -49,6 +49,56 @@ namespace Octokit
|
||||
Justification = "It's fiiiine. It's fine. Trust us.")]
|
||||
Task<Authorization> Get(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new authorization for the specified OAuth application if an authorization for that application
|
||||
/// doesn’t already exist for the user; otherwise, it fails.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method requires authentication.
|
||||
/// See the <a href="http://developer.github.com/v3/oauth/#get-or-create-an-authorization-for-a-specific-app">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="clientId">Client ID of the OAuth application for the token</param>
|
||||
/// <param name="clientSecret">The client secret</param>
|
||||
/// <param name="newAuthorization">Describes the new authorization to create</param>
|
||||
/// <exception cref="AuthorizationException">
|
||||
/// Thrown when the current user does not have permission to make this request.
|
||||
/// </exception>
|
||||
/// <exception cref="TwoFactorRequiredException">
|
||||
/// Thrown when the current account has two-factor authentication enabled and an authentication code is required.
|
||||
/// </exception>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns>The created <see cref="Authorization"/>.</returns>
|
||||
Task<ApplicationAuthorization> Create(
|
||||
string clientId,
|
||||
string clientSecret,
|
||||
NewAuthorization newAuthorization);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new authorization for the specified OAuth application if an authorization for that application
|
||||
/// doesn’t already exist for the user; otherwise, it fails.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method requires authentication.
|
||||
/// See the <a href="http://developer.github.com/v3/oauth/#get-or-create-an-authorization-for-a-specific-app">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="clientId">Client ID of the OAuth application for the token</param>
|
||||
/// <param name="clientSecret">The client secret</param>
|
||||
/// <param name="twoFactorAuthenticationCode">The two-factor authentication code in response to the current user's previous challenge</param>
|
||||
/// <param name="newAuthorization">Describes the new authorization to create</param>
|
||||
/// <exception cref="AuthorizationException">
|
||||
/// Thrown when the current user does not have permission to make this request.
|
||||
/// </exception>
|
||||
/// <exception cref="TwoFactorRequiredException">
|
||||
/// Thrown when the current account has two-factor authentication enabled and an authentication code is required.
|
||||
/// </exception>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns>The created <see cref="Authorization"/>.</returns>
|
||||
Task<ApplicationAuthorization> Create(
|
||||
string clientId,
|
||||
string clientSecret,
|
||||
NewAuthorization newAuthorization,
|
||||
string twoFactorAuthenticationCode);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new authorization for the specified OAuth application if an authorization for that application doesn’t already
|
||||
/// exist for the user; otherwise, returns the user’s existing authorization for that application.
|
||||
|
||||
@@ -376,6 +376,7 @@ namespace Octokit
|
||||
HttpMethod.Delete,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
CancellationToken.None,
|
||||
twoFactorAuthenticationCode);
|
||||
return response.HttpResponse.StatusCode;
|
||||
|
||||
Reference in New Issue
Block a user