• Stars
    star
    1,781
  • Rank 26,129 (Top 0.6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

OAuth Modules for Node.js - Supporting RSA, HMAC, PLAINTEXT, 2,3-Legged, 1.0a, Echo, XAuth, and 2.0

Mashape OAuth

OAuth Modules for Node.js - Supporting RSA, HMAC, PLAINTEXT, 2-Legged, 3-Legged, 1.0a, Echo, XAuth, and 2.0

OAuth Bible

If you're looking for the popular OAuth Bible, here it is. It extensively explains the multitude of OAuth flows and how OAuth works.

Installation

npm install mashape-oauth

Features

  • Handles binary responses
  • Handles gzipped responses
  • Supports having an empty oauth_token for 1.0a
  • Supports Plaintext, HMAC-SHA1, and RSA encryption for 1.0a
  • Object based parameter system and supports chaining
  • Code has been refactored to be more performant in loops, whiles, and callback structures.
  • Intuitive method naming, small footprint, and tested against test suites as well as hundreds of APIs.

Usage

Require the library and the one you wish to use.

  1. OAuth
  2. getOAuthRequestToken
  3. getOAuthAccessToken
  4. getXAuthAccessToken
  5. Request Methods
  6. OAuth2

Using OAuth (1.x, XAuth, Echo):

var OAuth = require('mashape-oauth').OAuth;
var oa = new OAuth({ /* … options … */ }, callback);
  • options Object OAuth request options
    • echo Object Optional If it exists we treat the request as OAuth Echo request. See Twitter
      • verifyCredentials String What is the credentials URI to delegate against?
    • realm String Optional Access Authentication Framework Realm Value, Commonly used in Echo Requests, allowed in all however: Section 3.5.1
    • requestUrl String Request Token URL. Section 6.1
    • accessUrl String Access Token URL. Section 6.2
    • callback String URL the Service Provider will use to redirect User back to Consumer after obtaining User Authorization has been completed. Section 6.2.1
    • consumerKey String The Consumer Key
    • consumerSecret String The Consumer Secret
    • version String Optional By spec this is 1.0 by default. Section 6.3.1
    • signatureMethod String Type of signature to generate, must be one of:
      • PLAINTEXT
      • RSA-SHA1
      • HMAC-SHA1
    • nonceLength Number Optional Length of nonce string. Default 32
    • headers Object Optional Headers to be sent along with request, by default these are already set.
    • clientOptions Object Optional Contains requestTokenHttpMethod and accessTokenHttpMethod value.
    • parameterSeperator String Optional Seperator for OAuth header parameters. Default is ,

getOAuthRequestToken() - Creating Request Token Call

oa.getOAuthRequestToken({ /* … parameters … */ }, callback);
  • parameters Object Optional Additional Headers you might want to pass along.
    • If omitted, you can treat parameters argument as callback and pass along a function as a single parameter.
  • callback Function Anonymous Function to be invoked upon response or failure.
Example
oa.getOAuthRequestToken(function (error, oauth_token, oauth_token_secret, results) {
  if (error)
    return res.send('Error getting OAuth Request Token: ' + error, 500);
  else
    // Usually a redirect happens here to the /oauth/authorize stage
    return res.send('Successfully Obtained Token & Secret: ' + oauth_token + ' & ' + oauth_token_secret, 200);
});

getOAuthAccessToken() - Creating OAuth Access Token Call

oa.getOAuthAccessToken(options, callback);
  • options Object
    • oauth_verifier String Verification code tied to the Request Token. Section 2.3
    • oauth_token String Request Token
    • oauth_token_secret String Request Token Secret, used to help generation of signatures.
    • parameters Object Optional Additional headers to be sent along with request.
    • callback Function Optional Method to be invoked upon result, over-ridden by argument if set.
  • callback Function Anonymous Function to be invoked upon response or failure, setting this overrides previously set callback inside options object.
Example
oa.getOAuthAccessToken({
  oauth_verifier: 'ssid39b',
  oauth_token: 'request_key',
  oauth_token_secret: 'request_secret'
}, function (error, token, secret, result) {
  if (error)
    return res.send('Error getting Auth Access Token: ' + error, 500);
  else
    // Usually you want to store the token and secret in a session and make your requests after this
    return res.send('Successfully Obtained Token & Secret: ' + token + ' & ' + secret, 200);
});

getXAuthAccessToken() - Creating XAuth Access Token Call

oa.getXAuthAccessToken(username, password, callback);
  • username String XAuth Username credentials of User obtaining a token on behalf of
  • password String XAuth Password credentials of User obtaining a token on behalf of
  • callback Function Anonymous Function to be invoked upon response or failure.
Example
oa.getXAuthAccessToken('nijikokun', 'abc123', function (error, oauth_token, oauth_token_secret, results) {
  if (error)
    return res.send('Error getting XAuth Access Token: ' + error, 500);
  else
    // Usually you want to store the token and secret in a session and make your requests after this
    return res.send('Successfully Obtained Token & Secret: ' + oauth_token + ' & ' + oauth_token_secret, 200);
});

Request Methods

oa.post(options, callback);
oa.get(options, callback);
oa.delete(options, callback);
oa.patch(options, callback);
oa.put(options, callback);

// Alternatively, you can use the old node-oauth style: (Where method is one of five above.)
oa.method(url, oauth_token, oauth_token_secret, body, type, parameters, callback);
  • options Object Contains Request Information
    • url String URL to be requested upon
    • oauth_token String Optional; Dependant upon request step, could be access, or request token.
    • oauth_token_secret String Optional; Dependant upon request step
    • body String Optional; Body information to be sent along with request.
    • type String Optional; Content Request Type
    • parameters Object Optional; Additional headers you wish to pass along with your request.
    • callback Function Optional; Method to be invoked upon result, over-ridden by argument if set.
  • callback Function Method to be invoked upon result, over-rides options callback.

Using OAuth2:

var OAuth2 = require('mashape-oauth').OAuth2;
var oa = new OAuth2({ /* … options … */ }, callback);
  • options Object OAuth Request Options
    • clientId String Client Identifier
    • clientSecret String Client Secret
    • baseUrl String Base url of OAuth request
    • authorizationUrl String Optional; Authorization endpoint, default is /oauth/authorize
    • authorizationMethod String Optional; Authorization Header Method, default is Bearer
    • accessTokenUrl String Optional; Access Token Endpoint, default is /oauth/access_token
    • accessTokenName String Optional; Access Token Parameter Name, default is access_token
    • headers Object Optional; Custom headers we wish to pass along

More Repositories

1

kong

🦍 The Cloud-Native API Gateway and AI Gateway.
Lua
38,724
star
2

insomnia

The open-source, cross-platform API client for GraphQL, REST, WebSockets and gRPC.
JavaScript
30,407
star
3

unirest-java

Unirest in Java: Simplified, lightweight HTTP client library.
Java
2,602
star
4

kubernetes-ingress-controller

🦍 Kong for Kubernetes: The official Ingress Controller for Kubernetes.
Go
2,127
star
5

swrv

Stale-while-revalidate data fetching for Vue
TypeScript
2,089
star
6

mockbin

Mock, Test & Track HTTP Requests and Response for Microservices
JavaScript
1,988
star
7

docker-kong

🐒 Docker distribution for Kong
Shell
1,392
star
8

unirest-php

Unirest in PHP: Simplified, lightweight HTTP client library.
PHP
1,282
star
9

httpsnippet

HTTP Request snippet generator for many languages & libraries
TypeScript
1,061
star
10

unirest-nodejs

Unirest in Node.js: Simplified, lightweight HTTP client library.
JavaScript
954
star
11

guardian

Remove the OAuth dance with one request.
JavaScript
640
star
12

deck

decK: Configuration management and drift detection for Kong
Go
437
star
13

unirest-python

Unirest in Python: Simplified, lightweight HTTP client library.
Python
432
star
14

apiembed

Embeddable API code snippets for your website, blog or API documentation
Pug
402
star
15

unirest-ruby

Unirest in Ruby: Simplified, lightweight HTTP client library.
Ruby
365
star
16

unirest-obj-c

Unirest in Objective-C: Simplified, lightweight HTTP client library.
Objective-C
276
star
17

kong-dist-kubernetes

Kubernetes managed Kong cluster
Shell
255
star
18

kong-manager

Admin GUI for Kong Gateway (Official)
TypeScript
242
star
19

kong-plugin

Simple template to get started with custom Kong plugins
Lua
238
star
20

charts

Helm chart for Kong
Mustache
224
star
21

lua-resty-worker-events

Cross Worker Events for Nginx in Pure Lua
Lua
190
star
22

unirest-net

Unirest in .NET: Simplified, lightweight HTTP client library.
C#
190
star
23

docs.konghq.com

🦍 Source code for docs.konghq.com website.
Ruby
186
star
24

kong-oauth2-hello-world

This is a simple node.js + express.js application that shows an authorization page for the OAuth 2.0 plugin on Kong.
JavaScript
173
star
25

kong-pongo

Tooling to run plugin tests with Kong and Kong Enterprise
Lua
154
star
26

lua-resty-dns-client

Lua DNS client, load balancer, and utility library
Lua
152
star
27

kongponents

🦍 Kong Vue Component Library
Vue
134
star
28

go-pdk

Kong Go Plugin Development Kit
Go
126
star
29

kong-vagrant

🐒 Vagrantfile for Kong testing and development
Shell
124
star
30

lua-resty-healthcheck

Healthcheck library for OpenResty to validate upstream service status
Lua
119
star
31

kong-plugin-prometheus

Prometheus plugin for Kong - this plugin has been moved into https://github.com/Kong/kong, please open issues and PRs in that repo
Lua
119
star
32

apiglossary

Open source glossary of API terms, acronyms and industry buzzwords.
95
star
33

go-kong

Go binding for Kong's admin API
Go
87
star
34

go-plugins

A collection of Kong plugins written in Go
Go
86
star
35

ngx_wasm_module

Nginx + WebAssembly
C
80
star
36

kong-terraform-aws

Kong Terraform Module for AWS
HCL
77
star
37

kong-build-tools

Build tools to package and release Kong
Shell
77
star
38

homebrew-kong

🐒 Homebrew tap for Kong
Ruby
69
star
39

kong-dist-cloudformation

🐒 Kong CloudFormation Stack
66
star
40

go-pluginserver

Kong Go Plugin Server
Go
66
star
41

kong-plugin-zipkin

A Kong plugin for propogating zipkin spans and reporting spans to a zipkin server - this plugin has been moved into https://github.com/Kong/kong, please open issues and PRs in that repo
Lua
60
star
42

kong-operator

Kong Operator for Kubernetes and OpenShift
Mustache
58
star
43

lua-multipart

Multipart Parser for Lua
Lua
55
star
44

mashape-php-library

Mashape PHP Server Library - Easily create an API in PHP. You can use it for existing services or brand new cloud components.
PHP
50
star
45

gateway-operator

Kubernetes Operator for Kong Gateways
Go
46
star
46

gojira

Multi-purpose tool to ease development and testing of Kong by using Docker containers
Shell
45
star
47

kong-python-pdk

Write Kong plugins in Python (Experimental)
Python
44
star
48

HARchiver

[Deprecated] Universal Lightweight Proxy for Galileo
OCaml
41
star
49

atc-router

Expression based matching library for Kong
Rust
41
star
50

koko

koko - Control Plane for Kong Gateway [open-source]
Go
41
star
51

unirest-website

Simplified, lightweight HTTP libraries in multiple languages
HTML
39
star
52

go-srp

Secure Remote Password library for Go
Go
38
star
53

tcpbin

TCP Request & Response Service, written in node.js
HTML
37
star
54

kong-plugin-acme

Let's Encrypt and ACMEv2 integration with Kong - this plugin has been moved into https://github.com/Kong/kong, please open issues and PRs in that repo
Lua
36
star
55

kong-portal-templates

Themes, components, and utilities to help you get started with the Kong Dev Portal.
CSS
35
star
56

kong-js-pdk

Kong PDK for Javascript and plugin server
JavaScript
35
star
57

kong-mesh-dist-kubernetes

Start Kong 1.0 as a K8s sidecar
Makefile
33
star
58

kubernetes-testing-framework

Golang Integration Testing Framework For Kubernetes APIs and Controllers.
Go
32
star
59

lua-kong-nginx-module

Nginx C module to allow deeper control of Nginx behaviors by Kong Lua code
Perl
32
star
60

demo-scene

🦍 a collection of demos and examples around Kong tools and technologies
JavaScript
30
star
61

konnect-portal

Konnect OSS Dev Portal
TypeScript
30
star
62

docker-java8

A Dockerfile for starting a container with Java 8 installed
30
star
63

Astronode-Broadcaster

A TCP replication server, or broadcaster, that replicates TCP commands to other TCP servers
Java
29
star
64

insomnia-docs

This repository houses all Insomnia documentation.
JavaScript
29
star
65

opentracing-lua

Opentracing Library for Lua
Lua
28
star
66

lua-resty-events

Inter process Pub/Sub pattern for Nginx worker processes
Raku
28
star
67

boss.js

Automatically load balance asyncronous jobs across multiple processes in a round-robin fashion.
JavaScript
27
star
68

kong-portal-cli

Kong Developer Portal CLI
TypeScript
25
star
69

lua-uuid

Lua library to generate UUIDs leveraging libuuid
Lua
25
star
70

lua-resty-aws

AWS SDK for OpenResty
Lua
24
star
71

lua-resty-lmdb

Safe API for manipulating LMDB databases using OpenResty/Lua.
C
24
star
72

kong-plugin-request-transformer

Kong request transformer plugin - this plugin has been moved into https://github.com/Kong/kong, please open issues and PRs in that repo
Lua
22
star
73

lua-resty-timer

Extended timers for OpenResty
Perl
22
star
74

lua-resty-counter

Lock-free counter for OpenResty
Perl
21
star
75

kong-plugin-session

🍪 Session plugin for Kong - this plugin has been moved into https://github.com/Kong/kong, please open issues and PRs in that repo
Lua
20
star
76

lua-pack

A library for packing and unpacking binary data.
C
20
star
77

go-apiops

Kong's Go based APIOps library
Go
19
star
78

swagger-ui-kong-theme

Plugin theme for Swagger-UI that adds snippets
JavaScript
19
star
79

terraform-provider-konnect

Terraform Provider for Kong Konnect
Go
18
star
80

api-log-format

Specification and examples of the new API logging format ALF
17
star
81

kong-plugin-serverless-functions

Kong Serverless Plugins - this plugin has been moved into https://github.com/Kong/kong, please open issues and PRs in that repo
Lua
17
star
82

apistatus

API status is a simple tool that checks if an API is online. http://apistatus.org
JavaScript
15
star
83

changelog-generator

a changelog generator focused on flexibility and ease of use
TypeScript
14
star
84

openresty-patches

Moved to https://github.com/Kong/kong-build-tools
Perl
14
star
85

kong-plugin-grpc-gateway

Kong Plugin to transcode REST request to gRPC - this plugin has been moved into https://github.com/Kong/kong, please open issues and PRs in that repo
Lua
14
star
86

lua-resty-consul-event

Consul Events HTTP API Wrapper
Perl
14
star
87

srp-js

Fork of node-srp modified to work in the browser
TypeScript
14
star
88

KongAir

An example Kong Konnect application deployed with Kong APIOps
JavaScript
13
star
89

harplayer

Replay HAR logs
JavaScript
13
star
90

kong-plugin-aws-lambda

AWS Lambda plugin - this plugin has been moved into https://github.com/Kong/kong, please open issues and PRs in that repo
Lua
13
star
91

openresty-build-tools

Moved to https://github.com/Kong/kong-build-tools
Shell
13
star
92

priority-updater

Tool to quickly create a plugin with an updated priority
Lua
13
star
93

jenkins-infrastructure

Cloudformation to create and update an ECS cluster that runs jenkins
Shell
12
star
94

httpbin

Python
12
star
95

kong-custom-plugin-workshop

Lua
12
star
96

kong-apisecops-redhat

Self-paced demo of APISecOps with ROSA and Kong Konnect
Jinja
12
star
97

version.lua

Simple version comparison library
Lua
11
star
98

kong-license

Kong Inc internal script to manage your local test license
Shell
11
star
99

kong-plugin-proxy-cache

HTTP Proxy Caching for Kong - this plugin has been moved into https://github.com/Kong/kong, please open issues and PRs in that repo
Lua
11
star
100

openapi2kong

Lib to convert OpenAPI specs into Kong specs
Lua
11
star