website logo
⌘K
πŸ–οΈIntroduction to hyper cloud
🍎Getting Started
😍What's New
Legacy Get Migration Guide
Blueberry Migration Guide
πŸ’ͺWorkshops
Deno Workshops
NodeJS Workshops
⚑Quickstarts
NodeJS Quickstarts
πŸ”ŒAPI Reference (hyper cloud)
🍎Basics
⚑hyper connect
πŸ”‘JWT Auth
πŸ’ΎData API
🏎️Cache API
πŸ”ŽSearch API
πŸ—„οΈStorage API
πŸ€“Queue API
πŸ”“Sign In
⚑Applications
βš™οΈSettings
πŸ”‘App Keys
πŸ‘₯Teams
Switching Between Accounts
Application Services
Application Service Instances
Adding a Queue Service
Adding a Search Service
Subscriptions
πŸ€‘Upgrade
πŸ“•Terminology
Parameters
πŸ’³Billing
Payment and Pricing Terms
πŸ’ΌLegal
Terms of Service
Acceptable Use Policy
Privacy Policy
πŸ•ΆοΈHyper Vision
Docs powered by
Archbee
API Reference (hyper cloud)

JWT Auth

6min

JSON Web Tokens (JWT) help secure communication between two systems. Signing a JWT allows the receiver to trust the sender or "issuer". This process provides a stateless approach to authentication. A key, secret, and connection string are created for you when you create a new hyper cloud application.

Don't share your secret or connection string!

Hyper uses the HS algorithm. HS algorithms require sharing a secret. Remember to keep the secret and connection string in a secure place. DO NOT SHARE ON VERSION CONTROL. DO NOT STORE IN YOUR SOURCE CODE WHERE IT CAN BE EXPOSED ON THE CLIENT SUCH AS THE WEB BROWSER.

When making raw HTTP calls using a utility such as cURL, you won't have the ability to use hyper-connect. Here's how to create a JSON Web Token (JWT) using your hyper cloud application's connection string and NodeJS.

  • Create a hyper app in the cloud. Go toΒ https://dashboard.hyper.io,Β sign in with your GitHub account, and create a new application.
  • Click the App Keysο»Ώ tab on the application page and copy the connection string.
Example hyper cloud app keys
Example hyper cloud app keys
ο»Ώ
  • Create a .env file. Within the .env file, create an environment variable named HYPER.
  • Paste the connection string as the value of the HYPER environment variable:
JS
|
HYPER=[connection string here]
ο»Ώ
  • Install the following dependencies using npm or yarn:
    • dotenv
    • jsonwebtoken
Node.js
|
require('dotenv').config()

const HYPER = process.env.HYPER
const jwt = require('jsonwebtoken')
const { username, password } = new URL(HYPER)

const payload = {
  sub: username
}

const algorithm = "HS256"

const signJWT = (payload, secret, algorithm) =>
  Promise.resolve(jwt.sign(payload, secret, { algorithm }));

signJWT(payload, password, algorithm).then(jwt => console.log({ jwt }))
ο»Ώ

Using hyper-connect

Consuming your hyper cloud application is secured using a Bearer token, provided in an Authorization header. See JWT Authο»Ώ for details on creating a bearer token using your hyper cloud application key pair.

Alternatively, Deno and NodeJS may simply use the hyper-connect module, which automatically generates a short-lived JWT for you on each request, using your hyper cloud application connection string.

Node.js
|
// hyper cloud urls follow this pattern: 
// https://cloud.hyper.io/:appname/:servicetype/:servicename
import { connect } from 'hyper-connect'

const hyper = connect(process.env.HYPER);

const result = await hyper.data.list({limit: 2}) // creates a short-lived jwt for you

console.log(result)

/* =>
{
  ok: true,
  docs: [
    {
      id: 'movie-1',
      title: 'Ghostbusters',
      type: 'movie',
      year: '1983'
    },
    { id: 'movie-2', title: 'Dune', type: 'movie', year: '1985' }
  ]
}
*/
ο»Ώ

ο»Ώ

Updated 16 Aug 2022
Did this page help you?
PREVIOUS
hyper connect
NEXT
Data API
Docs powered by
Archbee
TABLE OF CONTENTS
Don't share your secret or connection string!
Using hyper-connect
Docs powered by
Archbee