Alejandro Crosa

Auth0 and multiple environments for iOS apps

One thing that's a little odd about Auth0 is that you need to setup an Auth0.plist file to configure the service. This becomes a problem when you want to separate development from production environments where keys are different.

One trick to solve this requires setting up a “Run Phase” that can copy the final .plist at build time. Here's how you do it:

Go to settings

Click on the little + symbol and add the following “Run Script”:


RESOURCE_PATH=$SRCROOT/Authentication

FILENAME_IN_BUNDLE=Auth0.plist

BUILD_APP_DIR=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app

if [ "$CONFIGURATION" == "Debug" ]; then
cp $RESOURCE_PATH/Auth0-development.plist $BUILD_APP_DIR/$FILENAME_IN_BUNDLE
else
cp $RESOURCE_PATH/Auth0-production.plist $BUILD_APP_DIR/$FILENAME_IN_BUNDLE
fi

It should look like this:

Run Phase

Create the different files for development and production

Create a folder called “Authentication” to match the script above and add your new configuration files there. One for Auth0-development.plist and another for Auth0-production.plist.

They should like something like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>ClientId</key>
    <string>edb274d8c594429b8ccc684d79d771f6</string>
    <key>Domain</key>
    <string>dev-frs11rs2.us.auth0.com</string>
</dict>
</plist>

Done!, once you run your app in either development or production the right config file will be used.


10 months ago

Alejandro