After writing Basic Authentication using the platform, Layer0, I thought what if I wanted some users to land to google.com directly if they were from a given IP address or were using an Authorization Header?
I infer it as the "conditional" bypass to basic authorization on an app. The condition herein, can be anything, from matching a certain header to a matching body of a POST request!
For e.g., I want only the user(s) that request a page with cookie name
who with value
rishi, shall be allowed to view the contents of the page, while rest of the users are thrown to basic authorization. In this case, the "conditional" bypass is of being a user that requests with a cookie: who=rishi.
The following 8 steps will walk you through implementation of conditional basic authentication with Layer0, which is agnostic to the tech stack of your website.
In the example below, we'll be redirecting authenticated users to https://google.com.
Please complete the steps as in Basic Authentication using the platform, Layer0 to proceed further to the next step 👇🏻
In case you find dearth of apps to deploy, go back to the guide Basic Authentication using the platform, Layer0, skip the Step 2 in there and deploy the app via the following command:
npx @layer0/cli@latest deploy -e=to-google # -e or --environment
Click on Edit, and then scroll to the bottom of the page under "Split Testing", and then click on
Add Rule as in the image below:
This should open up a modal as below:
Add Criterion, and then from the dropdown, change
Cookie. On the right, one may now the respective
Cookie Name and the
value it should match. Also, as these users are already authenticated, you want them to be sent directly to google, hence change
current environment in the dropdown below to
Apply to save the rule.
To establish this, click on
Add Rule, under
100% of the traffic to face whatever is there in the
current Layer0 environment, as done in the image below:
Apply to save the rule.
As in the image below, all the users that fail to match the cookie, go to the environment that attemps to authenticate them, yet again.
To deploy your changes, click on
Activate button at the bottom of the page, and wait for the site to be re-deployed.
The example link still remains the same (let's not make it public that who=rishi cookie users can go to google.com directly 🤫): https://rishi-raj-jain-yg-basic-auth-example-default.layer0-limelight.link