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"
34 typedef struct oauth_s oauth_t;
36 int oauth_parse_json_token(char const *json, char *out_access_token,
37 size_t access_token_size, cdtime_t *expires_in);
44 /* oauth_create_google_json creates an OAuth object from JSON encoded
46 oauth_google_t oauth_create_google_json(char const *json, char const *scope);
48 /* oauth_create_google_file reads path, which contains JSON encoded service
49 * account credentials, and returns an OAuth object. */
50 oauth_google_t oauth_create_google_file(char const *path, char const *scope);
52 /* oauth_create_google_default looks for service account credentials in a couple
53 * of well-known places and returns an OAuth object if found. The well known
56 * - ${GOOGLE_APPLICATION_CREDENTIALS}
57 * - ${HOME}/.config/gcloud/application_default_credentials.json
59 oauth_google_t oauth_create_google_default(char const *scope);
61 /* oauth_destroy frees all resources associated with an OAuth object. */
62 void oauth_destroy(oauth_t *auth);
64 int oauth_access_token(oauth_t *auth, char *buffer, size_t buffer_size);