Skip to content

Commit

Permalink
Token Auth
Browse files Browse the repository at this point in the history
  • Loading branch information
jsernaque committed Aug 9, 2024
1 parent c55ef91 commit 04d0d77
Show file tree
Hide file tree
Showing 30 changed files with 13,223 additions and 41 deletions.
39 changes: 39 additions & 0 deletions examples/token-auth/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

# Edgio generated build directory
.edgio
35 changes: 35 additions & 0 deletions examples/token-auth/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "tokenauth:chrome",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}",
"preLaunchTask": "delay"
},
{
"type": "node",
"request": "launch",
"name": "tokenauth:edgio",
"cwd": "${workspaceFolder}",
"autoAttachChildProcesses": true,
"envFile": "${workspaceFolder}/.env.local",
"program": "${workspaceFolder}/node_modules/@edgio/cli",
"args": ["dev"]
}
],
"compounds": [
{
"name": "Debug [tokenauth]",
"configurations": [
"tokenauth:edgio",
"tokenauth:chrome"
]
}
]
}
15 changes: 15 additions & 0 deletions examples/token-auth/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "delay",
"command": "sleep 4",
"type": "shell",
"presentation": {
"reveal": "silent",
"panel": "shared"
},
"group": "none"
}
]
}
27 changes: 27 additions & 0 deletions examples/token-auth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Next.js Demo of Edgio Token Auth Functionality
This project demonstrates how Token Auth works with Edgio. For more details on this feature, visit [the docs](https://docs.edg.io/applications/v7/security/token_auth).

## Pages Available
This application exposes a few separate pages and one API endpoint:

* Main Page `/`: This page does not require an auth token.
* Secure Pages Landing Page `/secure`: This page does not require an auth token. All links on this page (except for the link to the homepage) DO require a valid token.
* Static Secure Page `/secure/static`: This page shows static data.
* Static Dynamic Page `/secure/dynamic`: This page shows dynamic data fetched from a third-party API.
* Token Generator/Decoder `/secure/generator`: This page allows the visitor to create and decode `ectoken`-compatible tokens.
* Current Token Information `/secure/info`: This page shows the decoded information about the token used to access the page.
* API route `/api/token`: This API route takes a GET request and returns a new token valid for all users but only for three minutes from when it was generated.

## How to Use
1. Navigate to the project homepage and click the link for the "Landing Page."
1. On the landing page, click the button to "Generate a temporary token."
1. Copy the generated token to your clipboard. Note that the links on this page will automatically update when a token is generated.
1. If you have generated a token via the client-side generator (see below), you can replace the token in the query string for any of the secure routes.

## Generating a Custom Token
You can also generate a custom token for this site. (Please note: the primary and backup tokens must be present in the Edgio environment variables for this feature to work properly.)
1. Navigate to the "Client-side Token Generator/Decoder" page.
1. Under the "Encode Token" section, enter the values you need for your token.
1. In that same section, enter one of the two keys you entered in your Token Auth settings for your Edgio environment.
1. Click "Encode Token."
1. The "Token value" field will contain the encoded token for your environment. Copy that token, and use it when navigating the demo site.
4 changes: 4 additions & 0 deletions examples/token-auth/edgio.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
connector: '@edgio/next',
organization: 'se-apps',
}
7 changes: 7 additions & 0 deletions examples/token-auth/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"paths": {
"@/*": ["./src/*"]
}
}
}
8 changes: 8 additions & 0 deletions examples/token-auth/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file was automatically added by edgio init.
// You should commit this file to source control.
const { withEdgio } = require('@edgio/next/config')

module.exports = (phase, config) =>
withEdgio({
// Write your Next config here
})
4 changes: 4 additions & 0 deletions examples/token-auth/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};

export default nextConfig;
Loading

0 comments on commit 04d0d77

Please sign in to comment.