]> diplodocus.org Git - nmh/blobdiff - h/oauth.h
Reverted commit 9a4b4a3d3b27fe4a7ff6d0b8724ce1c06b5917eb.
[nmh] / h / oauth.h
index a49cb4aced55cc56513dcca73f343a0b446cf467..ad6bd94054c981d92431f2d27b8fb2e52527262b 100644 (file)
--- a/h/oauth.h
+++ b/h/oauth.h
@@ -63,6 +63,10 @@ typedef enum {
     /* Attempting to refresh an access token without a refresh token. */
     MH_OAUTH_NO_REFRESH,
 
+
+    /* requested user not in cred file */
+    MH_OAUTH_CRED_USER_NOT_FOUND,
+
     /* error loading serialized credentials */
     MH_OAUTH_CRED_FILE
 } mh_oauth_err_code;
@@ -71,18 +75,48 @@ typedef struct mh_oauth_ctx mh_oauth_ctx;
 
 typedef struct mh_oauth_cred mh_oauth_cred;
 
+typedef struct mh_oauth_service_info mh_oauth_service_info;
+
+struct mh_oauth_service_info {
+    /* Name of service, so we can search static internal services array
+     * and for determining default credential file name. */
+    char *name;
+
+    /* Human-readable name of the service; in mh_oauth_ctx::svc this is not
+     * another buffer to free, but a pointer to either static SERVICE data
+     * (below) or to the name field. */
+    char *display_name;
+
+    /* [1] 2.2 Client Identifier, 2.3.1 Client Password */
+    char *client_id;
+    /* [1] 2.3.1 Client Password */
+    char *client_secret;
+    /* [1] 3.1 Authorization Endpoint */
+    char *auth_endpoint;
+    /* [1] 3.1.2 Redirection Endpoint */
+    char *redirect_uri;
+    /* [1] 3.2 Token Endpoint */
+    char *token_endpoint;
+    /* [1] 3.3 Access Token Scope */
+    char *scope;
+};
+
 /*
  * Do the complete dance for XOAUTH2 as used by POP3 and SMTP.
  *
  * Load tokens for svc from disk, refresh if necessary, and return the
- * base64-encoded client response.
+ * client response in client_response and client_response_len.
  *
  * If refreshing, writes freshened tokens to disk.
  *
  * Exits via adios on any error.
+ *
+ * Always returns OK for now, but in the future could return NOTOK on error.
  */
-char *
-mh_oauth_do_xoauth(const char *user, const char *svc, FILE *log);
+
+int
+mh_oauth_do_xoauth(const char *user, const char *svc, unsigned char **oauth_res,
+                  size_t *oauth_res_len, FILE *log);
 
 /*
  * Allocate and initialize a new OAuth context.
@@ -188,7 +222,7 @@ mh_oauth_cred_free(mh_oauth_cred *cred);
  * Never returns NULL.
  */
 const char *
-mh_oauth_cred_fn(mh_oauth_ctx *ctx);
+mh_oauth_cred_fn(const char *svc_name);
 
 /*
  * Serialize OAuth tokens to file.
@@ -196,7 +230,7 @@ mh_oauth_cred_fn(mh_oauth_ctx *ctx);
  * On error, return FALSE.
  */
 boolean
-mh_oauth_cred_save(FILE *fp, mh_oauth_cred *cred);
+mh_oauth_cred_save(FILE *fp, mh_oauth_cred *cred, const char *user);
 
 /*
  * Load OAuth tokens from file.
@@ -206,7 +240,7 @@ mh_oauth_cred_save(FILE *fp, mh_oauth_cred *cred);
  * On error, return NULL.
  */
 mh_oauth_cred *
-mh_oauth_cred_load(FILE *fp, mh_oauth_ctx *ctx);
+mh_oauth_cred_load(FILE *fp, mh_oauth_ctx *ctx, const char *user);
 
 /*
  * Return null-terminated SASL client response for XOAUTH2 from access token.
@@ -219,3 +253,11 @@ mh_oauth_cred_load(FILE *fp, mh_oauth_ctx *ctx);
 const char *
 mh_oauth_sasl_client_response(size_t *res_len,
                               const char *user, const mh_oauth_cred *cred);
+
+/*
+ * Retrieve the various entries for the OAuth mechanism
+ */
+
+boolean
+mh_oauth_get_service_info(const char *svc_name, mh_oauth_service_info *svcinfo,
+                         char *errbuf, size_t errbuflen);