项目作者: limit-zero

项目描述 :
Salesforce Marketing Cloud REST Authentication Service
高级语言: JavaScript
项目地址: git://github.com/limit-zero/marketing-cloud-auth.git
创建时间: 2018-10-11T01:21:55Z
项目社区:https://github.com/limit-zero/marketing-cloud-auth

开源协议:MIT License

下载


Salesforce Marketing Cloud (Fuel) Authentication

Authenticates and retrieves an access token for the Salesforce Marketing Cloud API. The token can be used for either the REST or SOAP API.

Features

  • Simple
  • Lightweight
  • Modern: utilizes ES6, Promises via async/await, Object rest spread, and node-fetch
    • As such, Node 8.6 or higher is required.

Install

Install with Yarn

  1. yarn add marketing-cloud-auth

Usage

To retrieve an access token, require the class and provide your API client ID and secret.

  1. // your-file.js
  2. const MarketingCloudAuth = require('marketing-cloud-auth');
  3. // Instantiate the `MarketingCloudAuth` class
  4. const auth = new MarketingCloudAuth({
  5. clientId: 'your-client-id',
  6. clientSecret: 'your-client-secret',
  7. });
  8. // Retrieve an access token using async/await...
  9. const retrieve = async () => {
  10. const token = await auth.retrieve();
  11. console.log(token);
  12. // Will output somthing similar to
  13. // { value: 'your-token', expiresIn: 3479 }
  14. }
  15. retrieve();
  16. // Or directly with a promise...
  17. auth.retrieve().then(token => console.log(token));

Subsequent calls to auth.retrieve will not make additional HTTP requests unless the token has expired or you explicitally force a new call via auth.retrieve({ force: true }).

Once the token is retrieved, you can include it in your REST API calls:

  1. GET https://www.exacttargetapis.com/platform/v1/endpoints
  2. Accept: application/json
  3. Authorization: Bearer YOUR_ACCESS_TOKEN

Or your SOAP calls

  1. <soap:header>
  2. <fueloauth>YOUR_ACCESS_TOKEN</fueloauth>
  3. </soap:header>
  4. <!-- OR (depending on which Salesforce docs you trust...) -->
  5. <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  6. <s:Header>
  7. <h:fueloauth xmlns="http://exacttarget.com"
  8. xmlns:h="http://exacttarget.com">
  9. YOUR_ACCESS_TOKEN
  10. </h:fueloauth>
  11. </s:Header>
  12. [...]
  13. </s:Envelope>

For more information, see