From 3d13e544f00199ebab98e5fe1dee92b6441b5167 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 28 Oct 2020 18:47:42 -0700 Subject: [PATCH] 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". --- ext/oauth-client/bin/local-redir.php | 28 +++++++++++++ ext/oauth-client/bin/local-redir.sh | 62 ++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 ext/oauth-client/bin/local-redir.php create mode 100755 ext/oauth-client/bin/local-redir.sh 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");' -- 2.25.1