Dynamic Redirection URLs After Login
-
Hi Nicu
I have implemented your rather good plug-in on our application (I will be buying you a coffee!) – but one of the features that is missing is Dynamic Redirection URLs after Automatic Login. Whilst you can specify a single custom URL, it would be useful to specify a dynamic URL (for example as a parameter) depending on the user context.
To make this work for me, I have currently modified redirectAfterLogin() in SimpleJWTLoginService.php to respond to a ‘redir’ parameter, e.g.
https://mydomain.com?rest_route=/simple-jwt-login/v1/autologin&redir=%2Fportal%2Fportal-nameprivate function redirectAfterLogin() { $requestParams = $this->request; if(isset( $requestParams['redir'] )) { // MP Added $url = $requestParams['redir']; } else { $redirect = $this->jwt_settings->getRedirect(); switch ( $redirect ) { case SimpleJWTLoginSettings::REDIRECT_HOMEPAGE: $url = $this->wordPressData->getSiteUrl(); break; case SimpleJWTLoginSettings::REDIRECT_CUSTOM: $url = $this->jwt_settings->getCustomRedirectURL(); break; case SimpleJWTLoginSettings::REDIRECT_DASHBOARD: default: $url = $this->wordPressData->getAdminUrl(); break; } } if ( $this->jwt_settings->getShouldIncludeRequestParameters() ) { $dangerousKeys = [ 'redir', 'rest_route', 'jwt', 'JWT', 'email', 'password', $this->jwt_settings->getAuthCodeKey() ]; foreach ( $dangerousKeys as $key ) { if ( isset( $requestParams[ $key ] ) ) { unset( $requestParams[ $key ] ); } } $url = $url . ( strpos( '?', $url ) !== false ? '&' : '?' ) . http_build_query( $requestParams ); } if ( $this->jwt_settings->isHookEnable( SimpleJWTLoginHooks::LOGIN_REDIRECT_NAME ) ) { $this->wordPressData->triggerAction( SimpleJWTLoginHooks::LOGIN_REDIRECT_NAME, $url, $this->request ); } $this->wordPressData->redirect( $url ); }Appreciate that their could be some low-level security implications with a redir param in the URL (albeit can be mitgated), it would be useful to have this as an option to enable on the dashboard. Related to this, it would also be good to have the option for the wp_users.user_url to be used as well as a redirection point.
If you implement this, it means I don’t have to do maintenance when you do updates 🙂
I do have an issue with registration meta_values not being added to the user, but I’ll raise that in a separate post.
Cheers
Matt
The topic ‘Dynamic Redirection URLs After Login’ is closed to new replies.