Skip to content
Snippets Groups Projects
auth_client.h 2.35 KiB
Newer Older
  • Learn to ignore specific revisions
  • ale's avatar
    ale committed
    #ifndef __libauthclient_authclient_h
    #define __libauthclient_authclient_h 1
    
    #include <curl/curl.h>
    
    struct auth_client;
    typedef struct auth_client* auth_client_t;
    
    #define AC_OK                           0
    #define AC_ERR_AUTHENTICATION_FAILURE  -1
    #define AC_ERR_OTP_REQUIRED            -2
    #define AC_ERR_BAD_RESPONSE            -3
    
    #define AC_ERR_FILE_NOT_FOUND          -4
    
    #define AC_ERR_NO_SERVERS              -5
    
    ale's avatar
    ale committed
    #define AC_ERR_CURL_BASE             -100
    
    #define auth_client_err_to_curl(e)     (-(e)+(AC_ERR_CURL_BASE))
    
    ale's avatar
    ale committed
    #define auth_client_err_from_curl(e)   ((AC_ERR_CURL_BASE)-(e))
    
    
    ale's avatar
    ale committed
    /*
     * Create a new auth client instance.
     *
     * @param service Service name
     * @param servers A comma-separated list of host:port auth server
     * addresses
     */
    
    auth_client_t auth_client_new(const char *service, const char *servers);
    
    ale's avatar
    ale committed
    
    /*
     * Free all resources associated with an auth client instance.
     */
    
    ale's avatar
    ale committed
    void auth_client_free(auth_client_t ac);
    
    ale's avatar
    ale committed
    
    /*
     * Return a human readable error string.
     *
     * @param err Error code returned by one of the auth_client_* methods
     */
    
    ale's avatar
    ale committed
    const char *auth_client_strerror(int err);
    
    ale's avatar
    ale committed
    
    /*
     * Set request verbosity.
     *
     * If verbose is set to 1, libcurl will dump the outbound requests to
     * standard error.
     *
     * @param ac Auth client
     * @param verbose Verbosity: 1 to enable, 0 to disable
     */
    
    void auth_client_set_verbose(auth_client_t ac, int verbose);
    
    ale's avatar
    ale committed
    
    /*
     * Set up SSL credentials, and enable HTTPS.
     *
     * @param ac Auth client
     * @param ca_file Path to the CA certificate (PEM format)
     * @param crt_file Path to the client certificate (PEM format)
     * @param key_file Path to the client certificate key
     */
    
    int auth_client_set_certificate(auth_client_t ac,
                                    const char *ca_file,
                                    const char *crt_file,
                                    const char *key_file);
    
    ale's avatar
    ale committed
    
    /*
     * Authenticate a user.
     *
     * @param ac Auth client
     * @param username Username
     * @param password Password
     * @param otp_token OTP token, if present (as a string)
     * @param source_ip Source IP of the user, where available
     * @param shard Shard identifier (as a string)
     */
    
    ale's avatar
    ale committed
    int auth_client_authenticate(auth_client_t ac,
                                 const char *username,
                                 const char *password,
                                 const char *otp_token,
    
                                 const char *source_ip,
    			     const char *shard);
    
    ale's avatar
    ale committed
    
    #endif