Skip to content

Commit 9c0b7b5

Browse files
author
Hans Zandbelt
committed
1.6.0rc3: improve OIDCMetadataURL handling
1 parent b333db5 commit 9c0b7b5

File tree

7 files changed

+43
-31
lines changed

7 files changed

+43
-31
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
10/2/2014
2+
- avoid crash when downloading metadata from OIDCProviderMetadataURL fails
3+
- set OIDCProviderMetadataURL retrieval interval to 24 hours
4+
- return error on configurations mixing OIDCProviderMetadataURL and OIDCMetadataDir
5+
- bump version number to 1.6.0rc3
6+
17
10/1/2014
28
- support provider configuration from a metadata URL (OIDCProviderMetadataURL)
39
- bump version number to 1.6.0rc2

README.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ Overview
99
--------
1010

1111
This module enables an Apache 2.x web server to operate as an [OpenID Connect]
12-
(http://openid.net/specs/openid-connect-core-1_0.html) *Relying Party* to an
13-
OpenID Connect *Provider*.
12+
(http://openid.net/specs/openid-connect-core-1_0.html) *Relying Party* (RP) to an
13+
OpenID Connect *Provider* (OP). It will enable users to authenticate at an OpenID
14+
Connect Provider, receive user identity information from the OP in a so called ID
15+
Token and pass the identity information (a.k.a. claims) in the ID Token to applications
16+
hosted and protected by the Apache web server.
1417

1518
The protected content and/or applications can be served by the Apache server
1619
itself or it can be served from elsewhere when Apache is configured as a reverse
@@ -91,7 +94,7 @@ have to enable the `Google+ API` under `APIs & auth` in the [Google API console]
9194
need to specify individual provider configuration entries manually, as in:
9295

9396
OIDCProviderIssuer accounts.google.com
94-
OIDCProviderAuthorizationEndpoint https://accounts.google.com/o/oauth2/auth[?hd=<your-domain>]
97+
OIDCProviderAuthorizationEndpoint https://accounts.google.com/o/oauth2/auth
9598
OIDCProviderTokenEndpoint https://accounts.google.com/o/oauth2/token
9699
OIDCProviderTokenEndpointAuth client_secret_post
97100
OIDCProviderUserInfoEndpoint https://www.googleapis.com/plus/v1/people/me/openIdConnect
@@ -192,15 +195,9 @@ This is also the OpenID Connect specified way of triggering 3rd party initiated
192195
to a specific provider when multiple OPs have been configured. In that case the callback
193196
may also contain a "login_hint" parameter with the login identifier the user might use to log in.
194197

195-
An additional **mod_auth_openidc** specific parameter named `auth_request_params` may also be passed in.
196-
Its value would contain dynamically determined custom parameters that need to be passed in the
197-
authorization requests and as such it is the runtime equivalent of the static OIDCAuthRequestParams
198-
configuration value and the `auth_request_params` in the `.conf` file. If you use more than one of the
199-
previous settings you'll need to make sure they do not conflict. Note that nested URL encoding is required
200-
e.g. passing both prompt=consent and max_auth_age=0 would result in:
201-
202-
auth_request_params=prompt%3Dconsent%26max_auth_age%3D0
203-
198+
An additional **mod_auth_openidc** specific parameter named `auth_request_params` may also be passed
199+
in, see the [Wiki](https://github.com/pingidentity/mod_auth_openidc/wiki#10-how-can-i-add-custom-parameters-to-the-authorization-request)
200+
for its usage.
204201

205202
###Sample Config for PingFederate OpenID Connect & OAuth 2.0
206203

auth_openidc.conf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
# (Optional)
2929
# When using multiple OpenID Connect Providers, possibly combined with Dynamic Client
3030
# Registration and account-based OP Discovery.
31-
# Directory that holds metadata files (must be writable for the Apache process/user)
32-
# When not specified, it is assumed that we use a single statically configured provider
33-
# as described under the section "OpenID Connect Provider" below.
31+
# Specifies the directory that holds metadata files (must be writable for the Apache process/user).
32+
# When not specified, it is assumed that we use a single statically configured provider as
33+
# described under the section "OpenID Connect Provider" below, most likely using OIDCProviderMetadataURL.
3434
#OIDCMetadataDir /var/cache/apache2/mod_auth_openidc/metadata
3535

3636
########################################################################################
@@ -101,7 +101,7 @@
101101
########################################################################################
102102

103103
# URL where OpenID Connect Provider metadata can be found (e.g. https://accounts.google.com/.well-known/openid-configuration)
104-
# The obtained metadata will be cached and refreshed every 4 hours.
104+
# The obtained metadata will be cached and refreshed every 24 hours.
105105
# If set, individual entries below will not have to be configured but can be used to override
106106
# settings obtained from the metadata.
107107
# If not set, the entries below will have to be configured for a single static OP configuration

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AC_INIT([mod_auth_openidc],[1.6.0rc2],[[email protected]])
1+
AC_INIT([mod_auth_openidc],[1.6.0rc3],[[email protected]])
22

33
AC_SUBST(NAMEVER, AC_PACKAGE_TARNAME()-AC_PACKAGE_VERSION())
44

src/config.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,12 @@ static int oidc_check_config_openid_openidc(server_rec *s, oidc_cfg *c) {
926926
// TODO: this depends on the configured OIDCResponseType now
927927
if (c->provider.client_secret == NULL)
928928
return oidc_check_config_error(s, "OIDCClientSecret");
929+
} else {
930+
if (c->provider.metadata_url != NULL) {
931+
oidc_serror(s,
932+
"only one of 'OIDCProviderMetadataURL' or 'OIDCMetadataDir' should be set");
933+
return HTTP_INTERNAL_SERVER_ERROR;
934+
}
929935
}
930936

931937
apr_uri_parse(s->process->pconf, c->redirect_uri, &r_uri);

src/mod_auth_openidc.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,16 @@ static char *oidc_get_state_cookie_name(request_rec *r, const char *state) {
201201
/*
202202
* return the static provider configuration, i.e. from a metadata URL or configuration primitives
203203
*/
204-
static oidc_provider_t *oidc_provider_static_config(request_rec *r, oidc_cfg *c) {
204+
static apr_byte_t oidc_provider_static_config(request_rec *r, oidc_cfg *c, oidc_provider_t **provider) {
205205

206206
json_t *j_provider = NULL;
207207
const char *s_json = NULL;
208208

209209
/* see if we should configure a static provider based on external (cached) metadata */
210-
if ((c->metadata_dir != NULL) || (c->provider.metadata_url == NULL))
211-
return &c->provider;
210+
if ((c->metadata_dir != NULL) || (c->provider.metadata_url == NULL)) {
211+
*provider = &c->provider;
212+
return TRUE;
213+
}
212214

213215
c->cache->get(r, OIDC_CACHE_SECTION_PROVIDER, c->provider.metadata_url,
214216
&s_json);
@@ -219,7 +221,7 @@ static oidc_provider_t *oidc_provider_static_config(request_rec *r, oidc_cfg *c)
219221
c->provider.metadata_url, &j_provider, &s_json) == FALSE) {
220222
oidc_error(r, "could not retrieve metadata from url: %s",
221223
c->provider.metadata_url);
222-
return NULL;
224+
return FALSE;
223225
}
224226

225227
// TODO: make the expiry configurable
@@ -233,22 +235,20 @@ static oidc_provider_t *oidc_provider_static_config(request_rec *r, oidc_cfg *c)
233235
j_provider = json_loads(s_json, 0, 0);
234236
}
235237

236-
oidc_debug(r, " # got metadata: %s", s_json);
238+
*provider = apr_pcalloc(r->pool, sizeof(oidc_provider_t));
239+
memcpy(*provider, &c->provider, sizeof(oidc_provider_t));
237240

238-
oidc_provider_t *provider = apr_pcalloc(r->pool, sizeof(oidc_provider_t));
239-
memcpy(provider, &c->provider, sizeof(oidc_provider_t));
240-
241-
if (oidc_metadata_provider_parse(r, j_provider, provider) == FALSE) {
241+
if (oidc_metadata_provider_parse(r, j_provider, *provider) == FALSE) {
242242
oidc_error(r, "could not parse metadata from url: %s",
243243
c->provider.metadata_url);
244244
if (j_provider)
245245
json_decref(j_provider);
246-
return NULL;
246+
return FALSE;
247247
}
248248

249249
json_decref(j_provider);
250250

251-
return provider;
251+
return TRUE;
252252
}
253253

254254
/*
@@ -258,7 +258,9 @@ static oidc_provider_t *oidc_get_provider_for_issuer(request_rec *r,
258258
oidc_cfg *c, const char *issuer) {
259259

260260
/* by default we'll assume that we're dealing with a single statically configured OP */
261-
oidc_provider_t *provider = oidc_provider_static_config(r, c);
261+
oidc_provider_t *provider = NULL;
262+
if (oidc_provider_static_config(r, c, &provider) == FALSE)
263+
return NULL;
262264

263265
/* unless a metadata directory was configured, so we'll try and get the provider settings from there */
264266
if (c->metadata_dir != NULL) {
@@ -1273,7 +1275,8 @@ static int oidc_authenticate_user(request_rec *r, oidc_cfg *c,
12731275
return oidc_discovery(r, c);
12741276

12751277
/* we're not using multiple OP's configured in a metadata directory, pick the statically configured OP */
1276-
provider = oidc_provider_static_config(r, c);
1278+
if (oidc_provider_static_config(r, c, &provider) == FALSE)
1279+
return HTTP_INTERNAL_SERVER_ERROR;
12771280
}
12781281

12791282
/* generate a random value to correlate request/response through browser state */

src/mod_auth_openidc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ APLOG_USE_MODULE(auth_openidc);
150150
#define OIDC_REQUIRE_NAME "claim"
151151

152152
/* defines for how long provider metadata will be cached */
153-
#define OIDC_CACHE_PROVIDER_METADATA_EXPIRY_DEFAULT 14400
153+
#define OIDC_CACHE_PROVIDER_METADATA_EXPIRY_DEFAULT 86400
154154

155155
/* cache sections */
156156
#define OIDC_CACHE_SECTION_JTI "jti"

0 commit comments

Comments
 (0)