|
| 1 | +# KnownUser.V3.Fastly |
| 2 | + |
| 3 | +The Queue-it Security Framework ensures that end-users are not able to access your online application without first |
| 4 | +going through the queue for any and all �protected� areas and paths on your sites. The queue system is implemented by |
| 5 | +adding a server-side (request-level) integration that protects your online application by redirecting users to a waiting |
| 6 | +room according to web traffic settings in the Queue-it GO Platform. After the integration is complete, queue system |
| 7 | +behavior and operations are managed in Queue-it�s Go Platform and/or via the Queue-it Admin API. |
| 8 | + |
| 9 | +This Fastly Queue-it Connector SDK (aka, Queue-it�s server-side KnownUser connector) uses a Compute@Edge service to |
| 10 | +integrate Queue-it's functionality into Fastly's network. |
| 11 | + |
| 12 | +A Wasm service is required to utilize this connector. |
| 13 | + |
| 14 | +> You can find the latest released version [here](https://github.com/queueit/KnownUser.V3.Fastly/releases/latest). |
| 15 | +
|
| 16 | +## Introduction |
| 17 | + |
| 18 | +When a user makes a request to your Fastly service our connector validates the request and if it is needed, it will |
| 19 | +redirect the user to the waiting room. After waiting in the waiting room, the queue engine will redirect the user back |
| 20 | +to your end attaching a query string parameter ( `queueittoken` ) containing some information about the user to the URL. |
| 21 | +The most important fields of the `queueittoken` are: |
| 22 | + |
| 23 | +- q - The user's unique queue identifier |
| 24 | +- ts - A timestamp of how long this redirect is valid |
| 25 | +- h - A hash of the token |
| 26 | + |
| 27 | +After the user returns from the queue, the connector will let the user continue his request to your backend ( without |
| 28 | +redirecting to the queue since the request has a valid queueittoken as query string) . |
| 29 | + |
| 30 | +## Installation |
| 31 | + |
| 32 | +There are two methods of installation: |
| 33 | + |
| 34 | +### As a standalone service |
| 35 | + |
| 36 | +- Go to the Fastly services page and create a new **Wasm** service. |
| 37 | +- Go to Domains and fill in the domain that you want your service to be reachable at. You may need to register a CNAME |
| 38 | + record if you have your own domain. |
| 39 | +- Then click on *Origins* and add a new host that has the hostname of your origin server. |
| 40 | + You need to edit the Host and name it **origin**. |
| 41 | +- Create a second host that has the hostname of `{yourCustomerId}.queue-it.net` and name it **queue-it**. |
| 42 | + Edit the host, go to advanced options and fill in the same hostname in **Override host** |
| 43 | +- Go to **Dictionaries** and create a new dictionary named `IntegrationConfiguration`. |
| 44 | + Add the following items in the dictionary: |
| 45 | + - customerId: Your customer ID |
| 46 | + - apiKey: The API key for your account |
| 47 | + - secret: Your KnownUserV3 secret |
| 48 | + - queueItOrigin: The name of the queue-it host, in this case it's `queue-it` |
| 49 | + You can find these values in the Go Queue-It self-service platform. |
| 50 | +- Download the latest package from the releases page and unarchive it. |
| 51 | +- Edit the `fastly.toml` file and copy the ID of your service (you can see this by opening up the service in Fastly) and |
| 52 | + replace __{YourServiceId}__ with it. |
| 53 | +- Archive the directory in the same format (tar.gz). |
| 54 | +- Go to `Package` in the Fastly service page and upload the package. |
| 55 | +- To finish up and deploy your service click on the **Activate** button. |
| 56 | + |
| 57 | +### Customizable service with the connector |
| 58 | + |
| 59 | +- Go to the Fastly services page and create a new **Wasm** service and copy it's ID. |
| 60 | +- Clone this repository and edit the fastly.toml file, make sure to set the `service_id` field to the ID you copied. |
| 61 | +- Then click on *Origins* and add a new host that has the hostname of your origin server. |
| 62 | + You can name the host **origin** or whatever you choose. |
| 63 | +- Create a host that has the hostname of `{yourCustomerId}.queue-it.net` and name it **queue-it**. |
| 64 | + Edit the host, go to advanced options and fill in the same hostname in **Override host** |
| 65 | +- Open up the service in Fastly and go to **Dictionaries** and create a new dictionary named `IntegrationConfiguration` |
| 66 | + . |
| 67 | + Add the following items in the dictionary: |
| 68 | + - customerId: Your customer ID |
| 69 | + - apiKey: The API key for your account |
| 70 | + - secret: Your KnownUserV3 secret |
| 71 | + - queueItOrigin: The name of the queue-it origin, in this case it's `queue-it` |
| 72 | + You can find these values in the Go Queue-It self-service platform. |
| 73 | +- You need to add some code that uses this connector. Here is an example: |
| 74 | + |
| 75 | +```ts |
| 76 | +import {Fastly} from "@fastly/as-compute"; |
| 77 | +import {onQueueITRequest, IntegrationDetails, onQueueITResponse} from "@queue-it/fastly"; |
| 78 | + |
| 79 | +const req = Fastly.getClientRequest(); |
| 80 | + |
| 81 | +// This is optional and can be null if it's specified in your Dictionary |
| 82 | +const integrationDetails = new IntegrationDetails( |
| 83 | + "QueueItOriginName", |
| 84 | + "CustomerId", |
| 85 | + "SecretKey", |
| 86 | + "ApiKey"); |
| 87 | +let res = onQueueITRequest(req, integrationDetails); |
| 88 | + |
| 89 | +if (res != null) { |
| 90 | + Fastly.respondWith(res!); |
| 91 | +} else { |
| 92 | + const myOrigin = 'Ticketania'; |
| 93 | + const cacheOverride = new Fastly.CacheOverride(); |
| 94 | + const res = Fastly.fetch(req, { |
| 95 | + backend: myOrigin, |
| 96 | + cacheOverride, |
| 97 | + }).wait(); |
| 98 | + onQueueITResponse(res); |
| 99 | + Fastly.respondWith(res); |
| 100 | +} |
| 101 | +``` |
| 102 | + |
| 103 | +- Build and deploy the package running `fastly compute build` and `fastly compute deploy` in the same directory. |
| 104 | +- Create desired waiting room(s), triggers, and actions in the Go Queue-It self-service platform. |
| 105 | + Then, save/publish the configuration. |
| 106 | + |
| 107 | +## Providing the queue configuration |
| 108 | + |
| 109 | +The recommended way is to use the Go Queue-it self-service portal to setup the configuration. The configuration |
| 110 | +specifies a set of Triggers and Actions. A Trigger is an expression matching one, more or all URLs on your website. When |
| 111 | +a user enter your website and the URL matches a Trigger-expression the corresponding Action will be triggered. The |
| 112 | +Action specifies which waiting room the users should be send to. In this way you can specify which waiting room(s) |
| 113 | +should protect which page(s) on the fly without changing the server-side integration. |
| 114 | + |
| 115 | +## Protecting AJAX calls |
| 116 | + |
| 117 | +If you need to protect AJAX calls beside page loads you need to add the below JavaScript tags to your pages: |
| 118 | + |
| 119 | +```html |
| 120 | + |
| 121 | +<script type="text/javascript" src="//static.queue-it.net/script/queueclient.min.js"></script> |
| 122 | +<script |
| 123 | + data-queueit-intercept-domain="{YOUR_CURRENT_DOMAIN}" |
| 124 | + data-queueit-intercept="true" |
| 125 | + data-queueit-c="{YOUR_CUSTOMER_ID}" |
| 126 | + type="text/javascript" |
| 127 | + src="//static.queue-it.net/script/queueconfigloader.min.js"> |
| 128 | +</script> |
| 129 | +``` |
0 commit comments