#undef DEF
#define DEF(type, name) \
SETTING_DEFINE_STRUCT_##type("oauth2_"#name, name, struct auth_oauth2_settings)
+#define DEF_SECS(type, name) \
+ SETTING_DEFINE_STRUCT_##type("oauth2_"#name, name##_secs, struct auth_oauth2_settings)
static const struct setting_define auth_oauth2_setting_defines[] = {
DEF(STR, tokeninfo_url),
DEF(STR, client_secret),
DEF(BOOLLIST, issuers),
DEF(STR, openid_configuration_url),
+ DEF_SECS(TIME, token_expire_grace),
DEF(BOOL, force_introspection),
DEF(BOOL, send_auth_headers),
DEF(BOOL, use_worker_with_mech),
.client_secret = "",
.issuers = ARRAY_INIT,
.openid_configuration_url = "",
+ .token_expire_grace_secs = 60,
.send_auth_headers = FALSE,
.use_worker_with_mech = FALSE,
};
db->oauth2_set.client_id = db->set->client_id;
db->oauth2_set.client_secret = db->set->client_secret;
db->oauth2_set.send_auth_headers = db->set->send_auth_headers;
+ db->oauth2_set.token_expire_grace_secs = db->set->token_expire_grace_secs;
if (!array_is_empty(&db->set->scope)) {
db->oauth2_set.scope =
p_array_const_string_join(db->pool, &db->set->scope, " ");
*/
const char *openid_configuration_url;
+ /* How many seconds after token expiration is it still allowed to
+ succeed the authentication. */
+ unsigned int token_expire_grace_secs;
+
/* Should introspection be done even if not necessary */
bool force_introspection;
/* Should we send service and local/remote endpoints as X-Dovecot-Auth headers */
iat, t0 + 1);
return -1;
}
- if (exp < t0) {
+ /* Allow using slightly expired token, in case client time isn't well
+ synced. */
+ if (exp < t0 - set->token_expire_grace_secs) {
*error_r = t_strdup_printf(
- "Token has expired (exp=%"PRId64" < %"PRId64")",
- exp, t0);
+ "Token has expired (exp=%"PRId64" < %"PRId64" - grace %u)",
+ exp, t0, set->token_expire_grace_secs);
return -1;
}
struct oauth2_validation_key_cache *key_cache;
/* valid issuer names */
const char *const *issuers;
+ /* How many seconds after token expiration is it still allowed to
+ succeed the authentication. */
+ unsigned int token_expire_grace_secs;
enum {
INTROSPECTION_MODE_GET_AUTH,