// 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 . #ifndef H_DISFLUID_INCLUDED #define H_DISFLUID_INCLUDED #include /** * 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