2 * collectd - src/utils_oauth.h
5 * Copyright (C) 2017 Florian Forster
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 * Florian Forster <octo at collectd.org>
27 #include "utils_time.h"
29 #ifndef GOOGLE_OAUTH_URL
30 #define GOOGLE_OAUTH_URL "https://www.googleapis.com/oauth2/v3/token"
33 #include <openssl/evp.h>
36 typedef struct oauth_s oauth_t;
38 int oauth_parse_json_token(char const *json, char *out_access_token,
39 size_t access_token_size, cdtime_t *expires_in);
41 oauth_t *oauth_create(char const *url, char const *iss, char const *scope,
42 char const *aud, EVP_PKEY *key);
43 oauth_t *oauth_create_p12(char const *url, char const *iss, char const *scope,
44 char const *aud, char const *file, char const *pass);
51 /* oauth_create_google_json creates an OAuth object from JSON encoded
53 oauth_google_t oauth_create_google_json(char const *json, char const *scope);
55 /* oauth_create_google_file reads path, which contains JSON encoded service
56 * account credentials, and returns an OAuth object. */
57 oauth_google_t oauth_create_google_file(char const *path, char const *scope);
59 /* oauth_create_google_default looks for service account credentials in a couple
60 * of well-known places and returns an OAuth object if found. The well known
63 * - ${GOOGLE_APPLICATION_CREDENTIALS}
64 * - ${HOME}/.config/gcloud/application_default_credentials.json
66 oauth_google_t oauth_create_google_default(char const *scope);
68 /* oauth_destroy frees all resources associated with an OAuth object. */
69 void oauth_destroy(oauth_t *auth);
71 int oauth_access_token(oauth_t *auth, char *buffer, size_t buffer_size);