summaryrefslogtreecommitdiff
path: root/src/client/Disfluid-0.h
blob: 5c7adb7ca5646c773d720814b1be592420e56267 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
// disfluid, implementation of the Solid specification
// Copyright (C) 2020, 2021  Vivien Kraus

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.

// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

#ifndef H_DISFLUID_INCLUDED
#define H_DISFLUID_INCLUDED

#include <stdlib.h>

/**
 * DisfluidApi:
 *
 * The context associated with the API is loaded when entering the
 * @disfluid_init function, and unloaded when the function exits.
 */
struct DisfluidApi;
typedef struct DisfluidApi DisfluidApi;

/**
 * DisfluidUser:
 *
 * @data: (closure):
 *
 * The type of function that is called with the API loaded.
 */
typedef void *(*DisfluidUser) (const DisfluidApi * api, void *data);

/**
 * disfluid_api_init:
 *
 * @func: (scope call) (not nullable): the function to call with the API loaded.
 * @data: (closure func): the second argument for @func.
 *
 * Call @func in a context where the API function can be called. The
 * API is unloaded when the function exits.
 *
 * Returns: (transfer none): the result of the callback.
 */
void *disfluid_api_init (DisfluidUser func, void *data);

/**
 * DisfluidClient:
 *
 * A client contains a client ID, redirection URI and an associated
 * key pair.
 */
struct DisfluidClient;
typedef struct DisfluidClient DisfluidClient;

/**
 * disfluid_api_make_client:
 * @api: the context loaded with @disfluid_init.
 * @client: (out) (transfer full): where to store the allocated client.
 * @client_id: the URI serving a client manifest on the web.
 * @redirect_uri: the URI where we can get back an authorization code.
 * @jwk: the JWK encoding of the key pair used by the client.
 *
 * Create a new client.
 */
void disfluid_api_make_client (const DisfluidApi * api,
			       DisfluidClient ** client,
			       const char *client_id,
			       const char *redirect_uri, const char *jwk);

/**
 * disfluid_client_free:
 * @client: the client to free.
 *
 * Delete @client.
 */
void disfluid_client_free (DisfluidClient * client);

/**
 * disfluid_client_copy:
 * @client: the client to copy.
 * @api: the API.
 * @copy: (out) (transfer full): the copy.
 */
void disfluid_client_copy (const DisfluidClient * client,
			   const DisfluidApi * api, DisfluidClient ** copy);

/**
 * disfluid_client_get_id:
 * @client: the client whose ID to lookup.
 * @api: the context API.
 * @start: how many URL prefix bytes to skip.
 * @max: how many URL bytes to copy after the skipped prefix.
 * @id: (array length=max) (element-type char): where to copy the URL bytes.
 * Returns: the total number of bytes in the URL.
 */
size_t disfluid_client_get_id (const DisfluidClient * client,
			       const DisfluidApi * api,
			       size_t start, size_t max, char *id);

/**
 * disfluid_client_get_redirect_uri:
 * @client: the client whose redirection URI to lookup.
 * @api: the context API.
 * @start: how many URL prefix bytes to skip.
 * @max: how many URL bytes to copy after the skipped prefix.
 * @redirect_uri: (array length=max) (element-type char): where to copy the URL bytes.
 * Returns: the total number of bytes in the URL.
 */
size_t disfluid_client_get_redirect_uri (const DisfluidClient * client,
					 const DisfluidApi * api,
					 size_t start, size_t max,
					 char *redirect_uri);

/**
 * disfluid_client_get_key_pair:
 * @client: the client whose key pair to dump.
 * @api: the context API.
 * @start: how many JWK prefix bytes to skip.
 * @max: how many JWK bytes to copy after the skipped prefix.
 * @jwk: (array length=max) (element-type char): where to copy the JWK bytes.
 * Returns: the total number of bytes in the JWK.
 */
size_t disfluid_client_get_key_pair (const DisfluidClient * client,
				     const DisfluidApi * api,
				     size_t start, size_t max, char *jwk);

/**
 * DisfluidAccount:
 *
 * An accounts is an ID, issuer, a key pair, and some optional tokens
 * (ID, access and refresh tokens).
 */
struct DisfluidAccount;
typedef struct DisfluidAccount DisfluidAccount;

/**
 * disfluid_api_make_account_full:
 * @api: the context loaded with @disfluid_init.
 * @account: (out) (transfer full): where to store the allocated account.
 * @subject: the URI serving the webid.
 * @issuer: the identity provider URI.
 * @key_pair: the key pair encoded as a JWK.
 * @id_token_header: (nullable): the ID token header, or NULL.
 * @id_token: (nullable): the ID token payload, or NULL.
 * @access_token: (nullable): the encoded access token, or NULL.
 * @refresh_token: (nullable): the refresh token, or NULL.
 *
 * Create a new account.
 */
void disfluid_api_make_account_full (const DisfluidApi * api,
				     DisfluidAccount ** account,
				     const char *subject,
				     const char *issuer,
				     const char *key_pair,
				     const char *id_token_header,
				     const char *id_token,
				     const char *access_token,
				     const char *refresh_token);

/**
 * disfluid_account_free:
 * @account: the account to free.
 *
 * Delete @account.
 */
void disfluid_account_free (DisfluidAccount * account);

/**
 * disfluid_account_copy:
 * @account: the account to copy.
 * @api: the API.
 * @copy: (out) (transfer full): the copy.
 */
void disfluid_account_copy (const DisfluidAccount * account,
			    const DisfluidApi * api, DisfluidAccount ** copy);

/**
 * disfluid_account_get_subject:
 * @account: the account whose subject to lookup.
 * @api: the context API.
 * @start: how many URL prefix bytes to skip.
 * @max: how many URL bytes to copy after the skipped prefix.
 * @subject: (array length=max) (element-type char): where to copy the URL bytes.
 * Returns: the total number of bytes in the URL.
 */
size_t disfluid_account_get_subject (const DisfluidAccount * account,
				     const DisfluidApi * api,
				     size_t start, size_t max, char *subject);

/**
 * disfluid_account_get_issuer:
 * @account: the account whose issuer to lookup.
 * @api: the context API.
 * @start: how many URL prefix bytes to skip.
 * @max: how many URL bytes to copy after the skipped prefix.
 * @issuer: (array length=max) (element-type char): where to copy the URL bytes.
 * Returns: the total number of bytes in the URL.
 */
size_t disfluid_account_get_issuer (const DisfluidAccount * account,
				    const DisfluidApi * api,
				    size_t start, size_t max, char *issuer);

/**
 * disfluid_account_get_key_pair:
 * @account: the account whose key pair to dump.
 * @api: the context API.
 * @start: how many JWK prefix bytes to skip.
 * @max: how many JWK bytes to copy after the skipped prefix.
 * @jwk: (array length=max) (element-type char): where to copy the JWK bytes.
 * Returns: the total number of bytes in the JWK.
 */
size_t disfluid_account_get_key_pair (const DisfluidAccount * account,
				      const DisfluidApi * api,
				      size_t start, size_t max, char *jwk);

/**
 * disfluid_account_get_id_token_header:
 * @account: the account whose ID token to lookup.
 * @api: the context API.
 * @start: how many JSON prefix bytes to skip.
 * @max: how many JSON bytes to copy after the skipped prefix.
 * @header: (array length=max) (element-type char): where to copy the JSON bytes.
 * Returns: the total number of bytes in the JSON.
 *
 * If the account does not have a valid ID token, 0 is returned.
 */
size_t disfluid_account_get_id_token_header (const DisfluidAccount * account,
					     const DisfluidApi * api,
					     size_t start, size_t max,
					     char *header);

/**
 * disfluid_account_get_id_token:
 * @account: the account whose ID token to lookup.
 * @api: the context API.
 * @start: how many JSON prefix bytes to skip.
 * @max: how many JSON bytes to copy after the skipped prefix.
 * @token: (array length=max) (element-type char): where to copy the JSON bytes.
 * Returns: the total number of bytes in the JSON.
 *
 * If the account does not have a valid ID token, 0 is returned.
 */
size_t disfluid_account_get_id_token (const DisfluidAccount * account,
				      const DisfluidApi * api,
				      size_t start, size_t max, char *token);

/**
 * disfluid_account_get_access_token:
 * @account: the account whose access token to lookup.
 * @api: the context API.
 * @start: how many JWT prefix bytes to skip.
 * @max: how many JWT bytes to copy after the skipped prefix.
 * @token: (array length=max) (element-type char): where to copy the JWT bytes.
 * Returns: the total number of bytes in the JWT.
 *
 * If the account does not have a valid access token, 0 is returned.
 */
size_t disfluid_account_get_access_token (const DisfluidAccount * account,
					  const DisfluidApi * api,
					  size_t start, size_t max,
					  char *token);

/**
 * disfluid_account_get_refresh_token:
 * @account: the account whose refresh token to lookup.
 * @api: the context API.
 * @start: how many prefix bytes to skip.
 * @max: how many bytes to copy after the skipped prefix.
 * @token: (array length=max) (element-type char): where to copy the refresh token bytes.
 * Returns: the total number of bytes in the refresh token.
 *
 * If the account does not have a valid refresh token, 0 is returned.
 */
size_t disfluid_account_get_refresh_token (const DisfluidAccount * account,
					   const DisfluidApi * api,
					   size_t start, size_t max,
					   char *token);

#endif