Skip to content

Added revoke functionality #456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Src/Notion.Client/Api/ApiEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
}
11 changes: 11 additions & 0 deletions Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,16 @@ Task<CreateTokenResponse> CreateTokenAsync(
CreateTokenRequest createTokenRequest,
CancellationToken cancellationToken = default
);

/// <summary>
/// Revokes an access token.
/// </summary>
/// <param name="revokeTokenRequest"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task RevokeTokenAsync(
RevokeTokenRequest revokeTokenRequest,
CancellationToken cancellationToken = default
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +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(
RevokeTokenRequest revokeTokenRequest,
CancellationToken cancellationToken = default)
{
var body = (IRevokeTokenBodyParameters)revokeTokenRequest;

var response = await _client.PostAsync<HttpResponseMessage>(
ApiEndpoints.AuthenticationUrls.RevokeToken(),
body,
cancellationToken: cancellationToken
);

if (!response.IsSuccessStatusCode)
{
throw new NotionApiException(response.StatusCode,
null,
"None success status code returned from revoke endpoint"
);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public interface IRevokeTokenBodyParameters
{
/// <summary>
/// The token to be revoked.
/// </summary>
[JsonProperty("token")]
string Token { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Notion.Client
{
public class RevokeTokenRequest : IRevokeTokenBodyParameters
{
public string Token { get; set; }
}
}