How to Build a One-Time QR Code with URL Redirect

Requirement

https://t.me/blacktechsharing/183161


Approach

A QR code is essentially a string of characters embedded in an image. This string can be a URL.

Since the QR code image has already been sent to others, and you can't go to their computer or phone to delete the image, how is a "one-time QR code" implemented?


If the QR code image stays the same, then the URL A corresponding to the QR code stays the same.

When you visit URL A, you're accessing a server. This server can make everyone who visits URL A redirect to a new URL B.

We define URL B as the URL that actually carries the real meaning. We let the server allow only the first visitor to URL A to be redirected to URL B; subsequent visits to URL A will have the redirection disabled.

This is how a "one-time QR code" is implemented.


For example, 

The URL with actual meaning is https://google.com

We set up a server, https://1way.eu.org

We make https://1way.eu.org/HcAx62 redirect to https://google.com and only redirect once.

We generate a QR code using https://1way.eu.org/HcAx62.

When someone scans this QR code, they will visit https://1way.eu.org/HcAx62, the system redirects them to https://google.com, and then the system records that this https://1way.eu.org/HcAx62 is now invalid.

If someone else scans this QR code, they will also visit https://1way.eu.org/HcAx62, but the system will tell them that this resource is no longer valid.


Implementation

worker.js

Add a configuration option snapchat_mode, disabled by default.


Before redirecting to the original link, delete this record. Then the next time someone looks it up, the record won't be found.


Full workflow of generating a one-time QR code using a QR code encoding/decoding tool


========

Postscript

Github: https://github.com/crazypeace/url-Shorten-Worker/

Comments