Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token Auth #155

Merged
merged 6 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**NOTICE TO CONTRIBUTORS**

This repository is not actively monitored and any pull requests made to this repository will be closed/ignored.

Please submit the pull request to [edgio-docs/edgio-examples](https://github.com/edgio-docs/edgio-examples) instead.
18 changes: 18 additions & 0 deletions examples/v7-token-auth-example/.github/workflows/edgio.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Deploy to Edgio

on:
workflow_dispatch:
push:

jobs:
deploy-to-edgio:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: if [ -f yarn.lock ]; then yarn install; else npm ci; fi
- run: if [ -f yarn.lock ]; then yarn edgio:deploy -- --token=$EDGIO_DEPLOY_TOKEN; else npm run edgio:deploy -- --token=$EDGIO_DEPLOY_TOKEN; fi
env:
EDGIO_DEPLOY_TOKEN: ${{secrets.EDGIO_DEPLOY_TOKEN}}
39 changes: 39 additions & 0 deletions examples/v7-token-auth-example/.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/v7-token-auth-example/.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/v7-token-auth-example/.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/v7-token-auth-example/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).

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

* Main Page `/`: This page does not require a token.
* Token Auth Landing Page `/secure`: This page does not require a token. All links on this page 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/v7-token-auth-example/edgio.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
connector: '@edgio/next',
organization: 'edgio-community',
}
7 changes: 7 additions & 0 deletions examples/v7-token-auth-example/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/v7-token-auth-example/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/v7-token-auth-example/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
Loading