From 744229db390be105aa419074f45e23d30ed6daa7 Mon Sep 17 00:00:00 2001 From: Mr-Bally <25254611+Mr-Bally@users.noreply.github.com> Date: Tue, 15 Apr 2025 10:39:47 +0000 Subject: [PATCH 1/5] Added revoke functionality --- Src/Notion.Client/Api/ApiEndpoints.cs | 1 + .../Authentication/IAuthenticationClient.cs | 11 ++++++++++ .../RevokeToken/AuthenticationClient.cs | 21 +++++++++++++++++++ .../Request/IRevokeTokenBodyParameters.cs | 13 ++++++++++++ .../RevokeToken/Request/RevokeTokenRequest.cs | 7 +++++++ 5 files changed, 53 insertions(+) create mode 100644 Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs create mode 100644 Src/Notion.Client/Api/Authentication/RevokeToken/Request/IRevokeTokenBodyParameters.cs create mode 100644 Src/Notion.Client/Api/Authentication/RevokeToken/Request/RevokeTokenRequest.cs diff --git a/Src/Notion.Client/Api/ApiEndpoints.cs b/Src/Notion.Client/Api/ApiEndpoints.cs index 4ed80bb1..86d703b3 100644 --- a/Src/Notion.Client/Api/ApiEndpoints.cs +++ b/Src/Notion.Client/Api/ApiEndpoints.cs @@ -135,6 +135,7 @@ public static string Create() public static class AuthenticationUrls { public static string CreateToken() => "/v1/oauth/token"; + public static string RevokeToken() => "/v1/oauth/revoke"; } } } diff --git a/Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs b/Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs index 0b4ebeb8..2aa3e7a8 100644 --- a/Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs +++ b/Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs @@ -18,5 +18,16 @@ Task CreateTokenAsync( CreateTokenRequest createTokenRequest, CancellationToken cancellationToken = default ); + + /// + /// Revokes an access token. + /// + /// + /// + /// + Task RevokeTokenAsync( + RevokeTokenRequest revokeTokenRequest, + CancellationToken cancellationToken = default + ); } } diff --git a/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs b/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs new file mode 100644 index 00000000..8cc5c85e --- /dev/null +++ b/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs @@ -0,0 +1,21 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace Notion.Client +{ + public sealed partial class AuthenticationClient + { + public async Task RevokeTokenAsync( + RevokeTokenRequest revokeTokenRequest, + CancellationToken cancellationToken = default) + { + var body = (IRevokeTokenBodyParameters)revokeTokenRequest; + + return (await _client.PostAsync( + ApiEndpoints.AuthenticationUrls.RevokeToken(), + body, + cancellationToken: cancellationToken + )).StatusCode; + } + } +} diff --git a/Src/Notion.Client/Api/Authentication/RevokeToken/Request/IRevokeTokenBodyParameters.cs b/Src/Notion.Client/Api/Authentication/RevokeToken/Request/IRevokeTokenBodyParameters.cs new file mode 100644 index 00000000..0a194516 --- /dev/null +++ b/Src/Notion.Client/Api/Authentication/RevokeToken/Request/IRevokeTokenBodyParameters.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public interface IRevokeTokenBodyParameters + { + /// + /// The token to be revoked. + /// + [JsonProperty("token")] + string Token { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Authentication/RevokeToken/Request/RevokeTokenRequest.cs b/Src/Notion.Client/Api/Authentication/RevokeToken/Request/RevokeTokenRequest.cs new file mode 100644 index 00000000..7e92ca01 --- /dev/null +++ b/Src/Notion.Client/Api/Authentication/RevokeToken/Request/RevokeTokenRequest.cs @@ -0,0 +1,7 @@ +namespace Notion.Client +{ + public class RevokeTokenRequest : IRevokeTokenBodyParameters + { + public string Token { get; set; } + } +} From a96af1ab55464f49fd03acdbe630a02fec6766e8 Mon Sep 17 00:00:00 2001 From: Sam-Ballantyne <25254611+Sam-Ballantyne@users.noreply.github.com> Date: Wed, 16 Apr 2025 10:25:02 +0100 Subject: [PATCH 2/5] Updates from PR review --- .../Authentication/IAuthenticationClient.cs | 4 ++-- .../RevokeToken/AuthenticationClient.cs | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs b/Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs index 2aa3e7a8..1973638f 100644 --- a/Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs +++ b/Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs @@ -18,14 +18,14 @@ Task CreateTokenAsync( CreateTokenRequest createTokenRequest, CancellationToken cancellationToken = default ); - + /// /// Revokes an access token. /// /// /// /// - Task RevokeTokenAsync( + Task RevokeTokenAsync( RevokeTokenRequest revokeTokenRequest, CancellationToken cancellationToken = default ); diff --git a/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs b/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs index 8cc5c85e..d9087aa4 100644 --- a/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs +++ b/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs @@ -1,21 +1,30 @@ +using System.Net.Http; using System.Threading; using System.Threading.Tasks; namespace Notion.Client { public sealed partial class AuthenticationClient - { - public async Task RevokeTokenAsync( + { + public async Task RevokeTokenAsync( RevokeTokenRequest revokeTokenRequest, CancellationToken cancellationToken = default) { var body = (IRevokeTokenBodyParameters)revokeTokenRequest; - - return (await _client.PostAsync( + + var response = await _client.PostAsync( ApiEndpoints.AuthenticationUrls.RevokeToken(), body, cancellationToken: cancellationToken - )).StatusCode; + ); + + if (!response.IsSuccessStatusCode) + { + throw new NotionApiException(response.StatusCode, + null, + "None success status code returned from revoke endpoint" + ); + } } } } From 0cc805772d78e0a4b7f2ad8d18992d8889bcf67b Mon Sep 17 00:00:00 2001 From: Mr-Bally <25254611+Mr-Bally@users.noreply.github.com> Date: Thu, 17 Apr 2025 16:24:51 +0100 Subject: [PATCH 3/5] Update from PR review --- .../Authentication/RevokeToken/AuthenticationClient.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs b/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs index d9087aa4..0d67057b 100644 --- a/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs +++ b/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs @@ -12,19 +12,11 @@ public async Task RevokeTokenAsync( { var body = (IRevokeTokenBodyParameters)revokeTokenRequest; - var response = await _client.PostAsync( + await _client.PostAsync( ApiEndpoints.AuthenticationUrls.RevokeToken(), body, cancellationToken: cancellationToken ); - - if (!response.IsSuccessStatusCode) - { - throw new NotionApiException(response.StatusCode, - null, - "None success status code returned from revoke endpoint" - ); - } } } } From bb62d1e3b5ec057fc951d46d8cc964e1f790700e Mon Sep 17 00:00:00 2001 From: Mr-Bally <25254611+Mr-Bally@users.noreply.github.com> Date: Thu, 17 Apr 2025 16:52:20 +0100 Subject: [PATCH 4/5] Added empty object for HttpClient --- .../Api/Authentication/RevokeToken/AuthenticationClient.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs b/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs index 0d67057b..2c4d2c28 100644 --- a/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs +++ b/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs @@ -12,11 +12,15 @@ public async Task RevokeTokenAsync( { var body = (IRevokeTokenBodyParameters)revokeTokenRequest; - await _client.PostAsync( + await _client.PostAsync( ApiEndpoints.AuthenticationUrls.RevokeToken(), body, cancellationToken: cancellationToken ); } } + + internal class RevokeTokenResponse + { + } } From c7349ed96f35d1f38633dfa9788bac05c72b195f Mon Sep 17 00:00:00 2001 From: Sam-Ballantyne <25254611+Sam-Ballantyne@users.noreply.github.com> Date: Thu, 17 Apr 2025 18:45:15 +0100 Subject: [PATCH 5/5] moved class into separate file --- .../Api/Authentication/RevokeToken/AuthenticationClient.cs | 5 ----- .../RevokeToken/Response/RevokeTokenResponse.cs | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 Src/Notion.Client/Api/Authentication/RevokeToken/Response/RevokeTokenResponse.cs diff --git a/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs b/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs index 2c4d2c28..c1f3ab9d 100644 --- a/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs +++ b/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs @@ -1,4 +1,3 @@ -using System.Net.Http; using System.Threading; using System.Threading.Tasks; @@ -19,8 +18,4 @@ await _client.PostAsync( ); } } - - internal class RevokeTokenResponse - { - } } diff --git a/Src/Notion.Client/Api/Authentication/RevokeToken/Response/RevokeTokenResponse.cs b/Src/Notion.Client/Api/Authentication/RevokeToken/Response/RevokeTokenResponse.cs new file mode 100644 index 00000000..428dd287 --- /dev/null +++ b/Src/Notion.Client/Api/Authentication/RevokeToken/Response/RevokeTokenResponse.cs @@ -0,0 +1,6 @@ +namespace Notion.Client +{ + internal class RevokeTokenResponse + { + } +}