@@ -280,10 +280,13 @@ static apr_byte_t oidc_unsolicited_proto_state(request_rec *r, oidc_cfg *c,
280280 char * target_uri = NULL ;
281281 apr_jwt_get_string (r -> pool , & jwt -> payload .value , "target_uri" , & target_uri );
282282 if (target_uri == NULL ) {
283- ap_log_rerror (APLOG_MARK , APLOG_ERR , 0 , r ,
284- "oidc_unsolicited_proto_state: no \"target_uri\" claim could be retrieved from JWT state, aborting" );
285- apr_jwt_destroy (jwt );
286- return FALSE;
283+ if (c -> default_url == NULL ) {
284+ ap_log_rerror (APLOG_MARK , APLOG_ERR , 0 , r ,
285+ "oidc_unsolicited_proto_state: no \"target_uri\" claim could be retrieved from JWT state and no OIDCDefaultURL is set, aborting" );
286+ apr_jwt_destroy (jwt );
287+ return FALSE;
288+ }
289+ target_uri = c -> default_url ;
287290 }
288291
289292 if (c -> metadata_dir != NULL ) {
@@ -1082,7 +1085,7 @@ static int oidc_discovery(request_rec *r, oidc_cfg *cfg) {
10821085 * authenticate the user to the selected OP, if the OP is not selected yet perform discovery first
10831086 */
10841087static int oidc_authenticate_user (request_rec * r , oidc_cfg * c ,
1085- oidc_provider_t * provider , const char * original_url ) {
1088+ oidc_provider_t * provider , const char * original_url , const char * login_hint ) {
10861089
10871090 ap_log_rerror (APLOG_MARK , OIDC_DEBUG , 0 , r ,
10881091 "oidc_authenticate_user: entering" );
@@ -1161,7 +1164,7 @@ static int oidc_authenticate_user(request_rec *r, oidc_cfg *c,
11611164
11621165 /* send off to the OpenID Connect Provider */
11631166 // TODO: maybe show intermediate/progress screen "redirecting to"
1164- return oidc_proto_authorization_request (r , provider , c -> redirect_uri , state , & proto_state );
1167+ return oidc_proto_authorization_request (r , provider , login_hint , c -> redirect_uri , state , & proto_state );
11651168}
11661169
11671170/*
@@ -1170,40 +1173,56 @@ static int oidc_authenticate_user(request_rec *r, oidc_cfg *c,
11701173static apr_byte_t oidc_is_discovery_response (request_rec * r , oidc_cfg * cfg ) {
11711174 /*
11721175 * prereq: this is a call to the configured redirect_uri, now see if:
1173- * the OIDC_RT_PARAM_NAME parameter is present and
1174- * the OIDC_DISC_ACCT_PARAM or OIDC_DISC_OP_PARAM is present
1176+ * the OIDC_DISC_OP_PARAM is present
11751177 */
1176- return (oidc_util_request_has_parameter (r , OIDC_DISC_RT_PARAM )
1177- && (oidc_util_request_has_parameter (r , OIDC_DISC_OP_PARAM )));
1178+ return oidc_util_request_has_parameter (r , OIDC_DISC_OP_PARAM );
11781179}
11791180
11801181/*
11811182 * handle a response from an IDP discovery page
11821183 */
11831184static int oidc_handle_discovery_response (request_rec * r , oidc_cfg * c ) {
11841185
1185- /* variables to hold the values (original_url+issuer or original_url+acct) returned in the response */
1186- char * issuer = NULL , * original_url = NULL ;
1186+ /* variables to hold the values returned in the response */
1187+ char * issuer = NULL , * target_link_uri = NULL , * login_hint = NULL ;
11871188 oidc_provider_t * provider = NULL ;
11881189
11891190 oidc_util_get_request_parameter (r , OIDC_DISC_OP_PARAM , & issuer );
1190- oidc_util_get_request_parameter (r , OIDC_DISC_RT_PARAM , & original_url );
1191+ oidc_util_get_request_parameter (r , OIDC_DISC_RT_PARAM , & target_link_uri );
1192+ oidc_util_get_request_parameter (r , OIDC_DISC_LH_PARAM , & login_hint );
11911193
11921194 // TODO: trim issuer/accountname/domain input and do more input validation
11931195
11941196 ap_log_rerror (APLOG_MARK , OIDC_DEBUG , 0 , r ,
1195- "oidc_handle_discovery_response: issuer=\"%s\", original_url =\"%s\"" ,
1196- issuer , original_url );
1197+ "oidc_handle_discovery_response: issuer=\"%s\", target_link_uri=\"%s\", login_hint =\"%s\"" ,
1198+ issuer , target_link_uri , login_hint );
11971199
1198- if (( issuer == NULL ) || ( original_url == NULL ) ) {
1200+ if (issuer == NULL ) {
11991201 return oidc_util_http_sendstring (r ,
12001202 "mod_auth_openidc: wherever you came from, it sent you here with the wrong parameters..." ,
12011203 HTTP_INTERNAL_SERVER_ERROR );
12021204 }
12031205
1206+ if (target_link_uri == NULL ) {
1207+ if (c -> default_url == NULL ) {
1208+ return oidc_util_http_sendstring (r ,
1209+ "mod_auth_openidc: 3rd party initiated SSO to this module without specifying a \"target_link_uri\" parameter is not possible because OIDCDefaultURL is not set." ,
1210+ HTTP_INTERNAL_SERVER_ERROR );
1211+ }
1212+ target_link_uri = c -> default_url ;
1213+ }
1214+
1215+ // TODO: check that target_link_uri matches OIDCCookieDomain and/or OIDCRedirectURI
1216+
12041217 /* find out if the user entered an account name or selected an OP manually */
12051218 if (strstr (issuer , "@" ) != NULL ) {
12061219
1220+ if (login_hint == NULL ) {
1221+ login_hint = apr_pstrdup (r -> pool , issuer );
1222+ //char *p = strstr(issuer, "@");
1223+ //*p = '\0';
1224+ }
1225+
12071226 /* got an account name as input, perform OP discovery with that */
12081227 if (oidc_proto_account_based_discovery (r , c , issuer , & issuer ) == FALSE) {
12091228
@@ -1234,7 +1253,7 @@ static int oidc_handle_discovery_response(request_rec *r, oidc_cfg *c) {
12341253 && (provider != NULL )) {
12351254
12361255 /* now we've got a selected OP, send the user there to authenticate */
1237- return oidc_authenticate_user (r , c , provider , original_url );
1256+ return oidc_authenticate_user (r , c , provider , target_link_uri , login_hint );
12381257 }
12391258
12401259 /* something went wrong */
@@ -1406,7 +1425,7 @@ static int oidc_check_userid_openidc(request_rec *r, oidc_cfg *c) {
14061425 }
14071426
14081427 /* no session (regardless of whether it is main or sub-request), go and authenticate the user */
1409- return oidc_authenticate_user (r , c , NULL , oidc_get_current_url (r , c ));
1428+ return oidc_authenticate_user (r , c , NULL , oidc_get_current_url (r , c ), NULL );
14101429}
14111430
14121431/*
0 commit comments