From: Tim Otten Date: Thu, 29 Oct 2020 01:47:42 +0000 (-0700) Subject: dev/core#2141 - Add "local-redir" stub for use as OAuth2 "Redirect URL" X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3d13e544f00199ebab98e5fe1dee92b6441b5167;p=civicrm-core.git dev/core#2141 - Add "local-redir" stub for use as OAuth2 "Redirect URL" If you are developing on a local HTTP system with virtual hosts, then many OAuth2 services won't recognize it as a local/dev URL. The "local-redir.sh" script runs a stub service that will be accepted as a local/dev "Redirect URL". --- diff --git a/ext/oauth-client/bin/local-redir.php b/ext/oauth-client/bin/local-redir.php new file mode 100644 index 0000000000..ab1bca9284 --- /dev/null +++ b/ext/oauth-client/bin/local-redir.php @@ -0,0 +1,28 @@ + http://example.local/civicrm/oauth/return +## https://public.example.com/my-return ==> http://example.local/civicrm/oauth/return +## +## The script "local-redir.sh" can help you setup an intermediate redirect. It will: +## +## 1. Launch a temporary HTTP service on "http://localhost:3000". +## 2. Configure CiviCRM to work with "http://localhost:3000". +## +################################################################################ + +## usage: local-redir.sh [ip-or-host[:port]] +## +## example#1: local-redir.sh +## example#2: local-redir.sh 127.0.0.1 +## example#3: local-redir.sh localhost:8000 + +############################################################################### +## Bootstrap + +## Determine the absolute path of the directory with the file +## usage: absdirname +function absdirname() { + pushd $(dirname $0) >> /dev/null + pwd + popd >> /dev/null +} + +BINDIR=$(absdirname "$0") +REDIRPHP="$BINDIR/local-redir.php" + +############################################################################### +## Main + +BIND=${1:-localhost:3000} +DEST=$(cv url -I civicrm/oauth-client/return) + +echo "local-redir.sh: Setup redirect proxy" +echo +echo "Intermediate URL: http://$BIND" +echo "Canonical URL: $DEST" +echo +echo "Update CiviCRM settings:" +cv api setting.create oauthClientRedirectUrl="http://$BIND" + +export DEST +php -S "$BIND" "$REDIRPHP" + +echo "Shutting down" +echo +echo "Reverting CiviCRM settings: oauthClientRedirectUrl" +cv ev 'Civi::settings()->revert("oauthClientRedirectUrl");'