}
}
+static void oauth2_introspection_delayed_error(struct oauth2_request *req)
+{
+ struct oauth2_introspection_result fail = {
+ .success = FALSE,
+ .error = req->delayed_error
+ };
+ oauth2_introspection_callback(req, &fail);
+ oauth2_request_free_internal(req);
+}
+
#undef oauth2_introspection_start
struct oauth2_request*
oauth2_introspection_start(const struct oauth2_settings *set,
pool_t pool = pool_alloconly_create_clean("oauth2 introspection", 1024);
struct oauth2_request *req =
p_new(pool, struct oauth2_request, 1);
- struct oauth2_introspection_result fail = {
- .success = FALSE,
- };
struct http_url *url;
const char *error;
if (http_url_parse(str_c(enc), NULL, HTTP_URL_ALLOW_USERINFO_PART, pool,
&url, &error) < 0) {
- fail.error = t_strdup_printf("http_url_parse(%s) failed: %s",
- str_c(enc), error);
- oauth2_introspection_callback(req, &fail);
+ req->delayed_error = p_strdup_printf(pool,
+ "http_url_parse(%s) failed: %s", str_c(enc), error);
+ req->to_delayed_error = timeout_add_short(0,
+ oauth2_introspection_delayed_error, req);
return req;
}
struct istream *is;
struct io *io;
+ const char *delayed_error;
+ struct timeout *to_delayed_error;
+
const char *username;
void (*json_parsed_cb)(struct oauth2_request*, bool success,
}
}
+static void oauth2_refresh_delayed_error(struct oauth2_request *req)
+{
+ struct oauth2_refresh_result fail = {
+ .success = FALSE,
+ .error = req->delayed_error
+ };
+ oauth2_refresh_callback(req, &fail);
+ oauth2_request_free_internal(req);
+}
+
#undef oauth2_refresh_start
struct oauth2_request*
oauth2_refresh_start(const struct oauth2_settings *set,
p_new(pool, struct oauth2_request, 1);
struct http_url *url;
const char *error;
- struct oauth2_refresh_result fail = {
- .success = FALSE
- };
req->pool = pool;
req->set = set;
if (http_url_parse(req->set->refresh_url, NULL, HTTP_URL_ALLOW_USERINFO_PART,
pool, &url, &error) < 0) {
- fail.error = t_strdup_printf("http_url_parse(%s) failed: %s",
- req->set->refresh_url, error);
- oauth2_refresh_callback(req, &fail);
+ req->delayed_error = p_strdup_printf(pool,
+ "http_url_parse(%s) failed: %s",
+ req->set->refresh_url, error);
+ req->to_delayed_error = timeout_add_short(0,
+ oauth2_refresh_delayed_error, req);
return req;
}
}
}
+static void oauth2_token_validation_delayed_error(struct oauth2_request *req)
+{
+ struct oauth2_token_validation_result fail = {
+ .success = FALSE,
+ .error = req->delayed_error
+ };
+ oauth2_token_validation_callback(req, &fail);
+ oauth2_request_free_internal(req);
+}
+
#undef oauth2_token_validation_start
struct oauth2_request*
oauth2_token_validation_start(const struct oauth2_settings *set,
struct http_url *url;
const char *error;
- struct oauth2_token_validation_result fail = {
- .success = FALSE
- };
pool_t pool = pool_alloconly_create_clean("oauth2 token_validation", 1024);
struct oauth2_request *req =
if (http_url_parse(str_c(enc), NULL, HTTP_URL_ALLOW_USERINFO_PART, pool,
&url, &error) < 0) {
- fail.error = t_strdup_printf("http_url_parse(%s) failed: %s",
- str_c(enc), error);
- oauth2_token_validation_callback(req, &fail);
+ req->delayed_error = p_strdup_printf(pool,
+ "http_url_parse(%s) failed: %s", str_c(enc), error);
+ req->to_delayed_error = timeout_add_short(0,
+ oauth2_token_validation_delayed_error, req);
return req;
}
void
oauth2_request_free_internal(struct oauth2_request *req)
{
+ if (req->to_delayed_error != NULL)
+ timeout_remove(&req->to_delayed_error);
pool_unref(&req->pool);
}