GithubHelp home page GithubHelp logo

teamvoxa / salesforce-oauth2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cangencer/salesforce-oauth2

0.0 5.0 0.0 102 KB

Salesforce OAuth2 Web Server Authentication Flow for Node.js

License: Apache License 2.0

JavaScript 100.00%

salesforce-oauth2's Introduction

salesforce-oauth2 -- Salesforce OAuth2 Web Server Authentication Flow

Abstract

A very lightweight implementation of the OAuth2 Web Server Authentication Flow for Salesforce for Node.js.

As Salesforce already provides a very robust REST API, the aim of this module is to provide a very thin wrapper for the authentication functionality only.

Install

npm install salesforce-oauth2

Usage

An example using the express web framework:

var express = require('express'),
	oauth2 = require('salesforce-oauth2');

var callbackUrl = "<your callback url>",
	consumerKey = "<your consumer key>",
	consumerSecret = "<your consumer secret>";

var app = express.createServer(express.logger());

app.get("/", function(request, response) {
	var uri = oauth2.getAuthorizationUrl({
		redirect_uri: callbackUrl,
		client_id: consumerKey,
		scope: 'api'
	});
	return response.redirect(uri);
});

app.get('/oauth/callback', function(request, response) {
	var authorizationCode = request.param('code');

	oauth2.authenticate({
		redirect_uri: callbackUrl,
		client_id: consumerKey,
		client_secret: consumerSecret,
		code: authorizationCode
	}, function(error, payload) {
		/*

		The payload should contain the following fields:
		
		id 				A URL, representing the authenticated user,
						which can be used to access the Identity Service.
		
		issued_at		The time of token issue, represented as the 
						number of seconds since the Unix epoch
						(00:00:00 UTC on 1 January 1970).
		
		refresh_token	A long-lived token that may be used to obtain
						a fresh access token on expiry of the access 
						token in this response. 

		instance_url	Identifies the Salesforce instance to which API
						calls should be sent.
		
		access_token	The short-lived access token.


		The signature field will be verified automatically and can be ignored.

		At this point, the client application can use the access token to authorize requests 
		against the resource server (the Force.com instance specified by the instance URL) 
		via the REST APIs, providing the access token as an HTTP header in 
		each request:

		Authorization: OAuth 00D50000000IZ3Z!AQ0AQDpEDKYsn7ioKug2aSmgCjgrPjG...
		*/
	});	
});

app.listen(3000, function() {
	console.log("Listening on 3000");
});

salesforce-oauth2's People

Contributors

cangencer avatar joshuadelange avatar chalaschek avatar

Watchers

 avatar James Cloos avatar Chris Hourihan avatar Brandon Cummings avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.