File tree Expand file tree Collapse file tree 10 files changed +171
-3
lines changed Expand file tree Collapse file tree 10 files changed +171
-3
lines changed Original file line number Diff line number Diff line change @@ -131,5 +131,10 @@ public static string Create()
131
131
return "/v1/comments" ;
132
132
}
133
133
}
134
+
135
+ public static class AuthenticationUrls
136
+ {
137
+ public static string CreateToken ( ) => "/v1/oauth/token" ;
138
+ }
134
139
}
135
140
}
Original file line number Diff line number Diff line change
1
+ namespace Notion . Client
2
+ {
3
+ public sealed partial class AuthenticationClient : IAuthenticationClient
4
+ {
5
+ private readonly IRestClient _client ;
6
+
7
+ public AuthenticationClient ( IRestClient restClient )
8
+ {
9
+ _client = restClient ;
10
+ }
11
+ }
12
+ }
Original file line number Diff line number Diff line change
1
+ using System . Threading ;
2
+ using System . Threading . Tasks ;
3
+
4
+ namespace Notion . Client
5
+ {
6
+ public sealed partial class AuthenticationClient
7
+ {
8
+ public async Task < CreateTokenResponse > CreateTokenAsync (
9
+ CreateTokenRequest createTokenRequest ,
10
+ CancellationToken cancellationToken = default )
11
+ {
12
+ var body = ( ICreateTokenBodyParameters ) createTokenRequest ;
13
+
14
+ return await _client . PostAsync < CreateTokenResponse > (
15
+ ApiEndpoints . AuthenticationUrls . CreateToken ( ) ,
16
+ body ,
17
+ cancellationToken : cancellationToken
18
+ ) ;
19
+ }
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ namespace Notion . Client
2
+ {
3
+ public class CreateTokenRequest : ICreateTokenBodyParameters
4
+ {
5
+ public string GrantType => "authorization_code" ;
6
+
7
+ public string Code { get ; set ; }
8
+
9
+ public string RedirectUri { get ; set ; }
10
+
11
+ public ExternalAccount ExternalAccount { get ; set ; }
12
+ }
13
+ }
Original file line number Diff line number Diff line change
1
+ using Newtonsoft . Json ;
2
+
3
+ namespace Notion . Client
4
+ {
5
+ /// <summary>
6
+ /// External account info
7
+ /// </summary>
8
+ public class ExternalAccount
9
+ {
10
+ /// <summary>
11
+ /// External account key
12
+ /// </summary>
13
+ [ JsonProperty ( "key" ) ]
14
+ public string Key { get ; set ; }
15
+
16
+ /// <summary>
17
+ /// External account name
18
+ /// </summary>
19
+ [ JsonProperty ( "name" ) ]
20
+ public string Name { get ; set ; }
21
+ }
22
+ }
Original file line number Diff line number Diff line change
1
+ using Newtonsoft . Json ;
2
+
3
+ namespace Notion . Client
4
+ {
5
+ public interface ICreateTokenBodyParameters
6
+ {
7
+ /// <summary>
8
+ /// A constant string: "authorization_code".
9
+ /// </summary>
10
+ [ JsonProperty ( "grant_type" ) ]
11
+ string GrantType { get ; }
12
+
13
+ /// <summary>
14
+ /// A unique random code that Notion generates to authenticate with your service,
15
+ /// generated when a user initiates the OAuth flow.
16
+ /// </summary>
17
+ [ JsonProperty ( "code" ) ]
18
+ string Code { get ; set ; }
19
+
20
+ /// <summary>
21
+ /// The "redirect_uri" that was provided in the OAuth Domain & URI section
22
+ /// of the integration's Authorization settings. Do not include this field if a
23
+ /// "redirect_uri" query param was not included in the Authorization URL
24
+ /// provided to users. In most cases, this field is required.
25
+ /// </summary>
26
+ [ JsonProperty ( "redirect_uri" ) ]
27
+ string RedirectUri { get ; set ; }
28
+
29
+ /// <summary>
30
+ /// External account details
31
+ /// </summary>
32
+ [ JsonProperty ( "external_account" ) ]
33
+ ExternalAccount ExternalAccount { get ; set ; }
34
+ }
35
+ }
Original file line number Diff line number Diff line change
1
+ using Newtonsoft . Json ;
2
+
3
+ namespace Notion . Client
4
+ {
5
+ public class CreateTokenResponse
6
+ {
7
+ [ JsonProperty ( "access_token" ) ]
8
+ public string AccessToken { get ; set ; }
9
+
10
+ [ JsonProperty ( "token_type" ) ]
11
+ public string TokenType { get ; set ; } = "bearer" ;
12
+
13
+ [ JsonProperty ( "bot_id" ) ]
14
+ public string BotId { get ; set ; }
15
+
16
+ [ JsonProperty ( "duplicated_template_id" ) ]
17
+ public string DuplicatedTemplateId { get ; set ; }
18
+
19
+ [ JsonProperty ( "owner" ) ]
20
+ public IBotOwner Owner { get ; set ; }
21
+
22
+ [ JsonProperty ( "workspace_icon" ) ]
23
+ public string WorkspaceIcon { get ; set ; }
24
+
25
+ [ JsonProperty ( "workspace_id" ) ]
26
+ public string WorkspaceId { get ; set ; }
27
+
28
+ [ JsonProperty ( "workspace_name" ) ]
29
+ public string WorkspaceName { get ; set ; }
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ using System . Threading ;
2
+ using System . Threading . Tasks ;
3
+
4
+ namespace Notion . Client
5
+ {
6
+ /// <summary>
7
+ /// Authentication client
8
+ /// </summary>
9
+ public interface IAuthenticationClient
10
+ {
11
+ /// <summary>
12
+ /// Creates an access token that a third-party service can use to authenticate with Notion.
13
+ /// </summary>
14
+ /// <param name="createTokenRequest"></param>
15
+ /// <param name="cancellationToken"></param>
16
+ /// <returns></returns>
17
+ Task < CreateTokenResponse > CreateTokenAsync (
18
+ CreateTokenRequest createTokenRequest ,
19
+ CancellationToken cancellationToken = default
20
+ ) ;
21
+ }
22
+ }
Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ namespace Notion.Client
5
5
[ SuppressMessage ( "ReSharper" , "UnusedMemberInSuper.Global" ) ]
6
6
public interface INotionClient
7
7
{
8
+ IAuthenticationClient AuthenticationClient { get ; }
9
+
8
10
IUsersClient Users { get ; }
9
11
10
12
IDatabasesClient Databases { get ; }
@@ -29,7 +31,8 @@ public NotionClient(
29
31
IPagesClient pages ,
30
32
ISearchClient search ,
31
33
ICommentsClient comments ,
32
- IBlocksClient blocks )
34
+ IBlocksClient blocks ,
35
+ IAuthenticationClient authenticationClient )
33
36
{
34
37
RestClient = restClient ;
35
38
Users = users ;
@@ -38,8 +41,11 @@ public NotionClient(
38
41
Search = search ;
39
42
Comments = comments ;
40
43
Blocks = blocks ;
44
+ AuthenticationClient = authenticationClient ;
41
45
}
42
46
47
+ public IAuthenticationClient AuthenticationClient { get ; }
48
+
43
49
public IUsersClient Users { get ; }
44
50
45
51
public IDatabasesClient Databases { get ; }
Original file line number Diff line number Diff line change @@ -12,8 +12,9 @@ public static NotionClient Create(ClientOptions options)
12
12
, new DatabasesClient ( restClient )
13
13
, new PagesClient ( restClient )
14
14
, new SearchClient ( restClient )
15
- , blocks : new BlocksClient ( restClient )
16
- , comments : new CommentsClient ( restClient )
15
+ , new CommentsClient ( restClient )
16
+ , new BlocksClient ( restClient )
17
+ , new AuthenticationClient ( restClient )
17
18
) ;
18
19
}
19
20
}
You can’t perform that action at this time.
0 commit comments