diff --git a/Octokit/Clients/AuthorizationsClient.cs b/Octokit/Clients/AuthorizationsClient.cs index 59865c6a..1cc0fe0e 100644 --- a/Octokit/Clients/AuthorizationsClient.cs +++ b/Octokit/Clients/AuthorizationsClient.cs @@ -175,6 +175,81 @@ namespace Octokit throw new TwoFactorChallengeFailedException(e); } } + /// + /// + /// + /// This method requires authentication. + /// See the API documentation for more information. + /// + /// Client ID of the OAuth application for the token + /// The client secret + /// The OAuth token to check + /// The valid . + public async Task CheckApplicationAuthentication(string clientId, string accessToken) + { + Ensure.ArgumentNotNullOrEmptyString(clientId, "clientId"); + Ensure.ArgumentNotNullOrEmptyString(accessToken, "accessToken"); + + return await ApiConnection.Get( + ApiUrls.ApplicationAuthorization(clientId, accessToken)); + } + + /// + /// Resets a valid OAuth token for an OAuth application without end user involvment. + /// + /// + /// This method requires authentication. + /// See the API documentation for more information. + /// + /// ClientID of the OAuth application for the token + /// The OAuth token to reset + /// The valid with a new OAuth token + public async Task ResetApplicationAuthentication(string clientId, string accessToken) + { + Ensure.ArgumentNotNullOrEmptyString(clientId, "clientId"); + Ensure.ArgumentNotNullOrEmptyString(accessToken, "accessToken"); + + var requestData = new { }; + + return await ApiConnection.Post( + ApiUrls.ApplicationAuthorization(clientId, accessToken), requestData); + } + + /// + /// Revokes a single OAuth token for an OAuth application. + /// + /// + /// This method requires authentication. + /// See the API documentation for more information. + /// + /// ClientID of the OAuth application for the token + /// The OAuth token to revoke + /// A for the request's execution. + public Task RevokeApplicationAuthentication(string clientId, string accessToken) + { + Ensure.ArgumentNotNullOrEmptyString(clientId, "clientId"); + Ensure.ArgumentNotNullOrEmptyString(accessToken, "accessToken"); + + return ApiConnection.Delete( + ApiUrls.ApplicationAuthorization(clientId, accessToken)); + } + + /// + /// Revokes every OAuth token for an OAuth application. + /// + /// + /// This method requires authentication. + /// See the API documentation for more information. + /// + /// ClientID of the OAuth application for the token + /// A for the request's execution. + public Task RevokeAllApplicationAuthentications(string clientId) + { + Ensure.ArgumentNotNullOrEmptyString(clientId, "clientId"); + + return ApiConnection.Delete( + ApiUrls.ApplicationAuthorization(clientId)); + } /// /// Updates the specified . diff --git a/Octokit/Helpers/ApiUrls.Authorizations.cs b/Octokit/Helpers/ApiUrls.Authorizations.cs index 63f97dab..124b84ff 100644 --- a/Octokit/Helpers/ApiUrls.Authorizations.cs +++ b/Octokit/Helpers/ApiUrls.Authorizations.cs @@ -48,5 +48,15 @@ namespace Octokit { return "authorizations/clients/{0}/{1}".FormatUri(clientId, fingerprint); } + + public static Uri ApplicationAuthorization(string clientId) + { + return "applications/{0}/tokens".FormatUri(clientId); + } + + public static Uri ApplicationAuthorization(string clientId, string accessToken) + { + return "appliations/{0}/tokens/{1}".FormatUri(clientId, accessToken); + } } }