Skip to content

CleverCloud/oauth1-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clever Cloud OAuth1 Example

A minimal Node.js application demonstrating the OAuth 1.0a flow with the Clever Cloud API. Zero external dependencies.

Prerequisites

Deploy on Clever Cloud

Install Clever Tools and log in:

# Alternative install methods:
# https://www.clever.cloud/developers/doc/cli/install/
npm i -g clever-tools
clever login

Clone this repository and create the application:

git clone https://github.com/CleverCloud/oauth1-example
cd oauth1-example

clever create --type node

# Must match the base URL configured in your OAuth consumer
# For production, use a custom domain instead of cleverapps.io
clever domain add <example-domain>.cleverapps.io
clever domain favourite set <example-domain>.cleverapps.io

clever env set OAUTH_CONSUMER_KEY "your_consumer_key"
clever env set OAUTH_CONSUMER_SECRET "your_consumer_secret"
clever env set APP_HOST "$(clever domain favourite)"

clever deploy
clever open

Local development

Create a .env file with your OAuth consumer credentials (base URL set to http://localhost:8080):

OAUTH_CONSUMER_KEY=your_consumer_key
OAUTH_CONSUMER_SECRET=your_consumer_secret
npm run dev

The app listens on http://localhost:8080 by default. Set PORT to change it.

How it works

  1. User clicks "Login with Clever Cloud"
  2. Server obtains a request token and redirects to the Clever Cloud authorization page
  3. After approval, Clever Cloud redirects back with a verifier
  4. Server exchanges the verifier for an access token
  5. Tokens are stored in the browser's localStorage
  6. Client calls /api/self, server proxies the request to GET /v2/self with OAuth1 signing

Project structure

├── server.js        # HTTP server and routing
├── oauth.js         # OAuth1 HMAC-SHA512 signing and flow
└── public/
    ├── index.html   # Page structure
    ├── style.css    # Design system
    ├── app.js       # Client-side logic and rendering
    └── logo.svg     # Clever Cloud logo

See the full OAuth1 documentation for details on the protocol.

About

Demo application to integrate Clever Cloud OAuth login with Node.js

Topics

Resources

Stars

Watchers

Forks

Contributors