Giter Site home page Giter Site logo

salesforce-marketingcloud / fuelsdk-node-auth Goto Github PK

View Code? Open in Web Editor NEW
14.0 29.0 17.0 623 KB

Node authentication library for accessing the Salesforce Marketing Cloud APIs. Used in REST and SOAP client

License: BSD 3-Clause "New" or "Revised" License

JavaScript 100.00%
fuel javascript nodejs marketing-cloud salesforce exacttarget

fuelsdk-node-auth's People

Contributors

dougwilson avatar greenkeeper[bot] avatar kejandre avatar kellyjandrews avatar manivinesh avatar sf-csarov avatar sfdrogojan avatar svc-scm avatar vernak2539 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fuelsdk-node-auth's Issues

Use event emitter

will make notifying clients easier, and we will have less callback "hell"

update readme and docs

Need to have a better layout for docs/readme. Want to add methods and all available options.

change getAccessToken api

FROM

getAccessToken( requestOptions, forceRequest, callback )

TO

getAccessToken( options, callback )

options would have options.request and options.force.

Changing it to this would allow us to check the first argument and if it's a function it's the callback, otherwise it's options and use them. So we could do

getAccessToken( function( err, body ) {});

OR

getAccessToken( options, function( err, body ) {});

Remove requests from this library

Based on Alex's suggestion, should we pull the requesting mechanisms from this library? Should we pull it all together, or just the SOAP/REST requests, leaving the generic "request" functionality? Thoughts?

Initialize from JWT?

should we pursue a feature where we allow the client to be initialized via a JWT? Might be useful if we have people set up in app center

Supporting /v2/token Auth Url

Introduction:
Hello! I am just starting out with integrating with SFMC for my company and I am trying to use this SDK along with FuelSDK-Node-REST. At the start I am just trying to understand the best ways I can use these SDKs.

Task:
Easily Initialize this class for use. At the moment I feel like I'm really doing some wonky things to be able to make this Class work how I need it to. I think the root of my issues come from this class seems to be set up to work with the /v1/requestToken route for authentication, but I do not have a legacy package as such I need to be able to use /v2/token and the syntax between these to varies. Through a lot of digging into how the code works and lots of trial an error I can use the /v2 route.

My usage:
To just have a simple initialization process this how I get getAccessToken to work.

// Simple Initialization 
const options = {
  clientId: myClientId,
  clientSecret: myClientSecret,
  authUrl: authUrl // https://YOUR_SUBDOMAIN.auth.marketingcloudapis.com/v2/token
}

const AuthClient = new FuelAuth(options)
const authOptions = {
      force: true,
      json: {
        grant_type: 'client_credentials',
        client_id: myClientId,
        client_secret: myClientSecret
      }
    }
    AuthRest.getAccessToken(authOptions)
      .then(resp => {
           // I can see a valid response and my access token is under access_token
      })
      .catch(err => {
          // handle error
      })

If I wanted to make sure not to pass any options to getAccessToken, then this is what I did to get it to work.

// Complicated Initialization 
const options = {
  clientId: myClientId,
  clientSecret: myClientSecret,
  authUrl: authUrl, // https://YOUR_SUBDOMAIN.auth.marketingcloudapis.com/v2/token
  globalReqOptions: {
    json: {
      grant_type: 'client_credentials',
      client_id: myClientId,
      client_secret: myClientSecret
    }
  }

const AuthClient = new FuelAuth(options)
    AuthRest.getAccessToken()
      .then(resp => {
           // I can see a valid response and my access token is under access_token
      })
      .catch(err => {
          // handle error
      })

The Observation:
The module needs to be updated to be able to fluidly use both routes without much change to the client using this already. I think by changing the format of options in the constructor or even how the request calls are made will help make this more user friendly. I also think it should give a standard response to whoever is asking for the token. (I have some understanding how the base class is working, so I am also trying to think of the best way to achieve this.)

Takeaway:
The way things are now really do not allow for me to use FuelSDK-Node-Rest fluidly as I would like. The fact that FuelSDK-Node-Rest makes assumptions on the format of the response is where I am getting blocked. I cannot make any calls using the REST module since I get a Error: No access token which is happening because of how that code is looking for the access token. It expects accessToken and since v2 returns access_token that check for the token fails.

Hoping to get more insight on this!

Regards

Need to provide a Refresh token flow for long-running processes

I see we have a getAccessToken, and I haven't tested if I can do it with this implementation, but I know that we have customers and developers who are going to want to be able to instantiate this module and implement a long lived token feature...with minimal effort.

Authentication error while making request

I'm trying to make a simple GET request using OAuth 2.0 and grant_type: 'client_credentials' but i keep getting an error. I followed the readme doc to initialize and make a request like below.

const FuelRest = require("fuel-rest");

const options = {
  auth: {
    clientId: "CLIENT_ID_HERE",
    clientSecret: "CLIENT_SECRET_HERE",
    authUrl:
      "https://MY_AUTH_URL.auth.marketingcloudapis.com/v2/token/", //Tried without '/v2/token/' also
  },
  origin: "https://MY_ORIGIN.rest.marketingcloudapis.com/",
};

const RestClient = new FuelRest(options);

const getOpts = {
  uri: "/platform/v1/endpoints",
  headers: {},
  // other request options
};

RestClient.get(getOpts)
  .then(function (response) {
    var result = response && response.body ? response.body : response;
    console.log(result);
  })
  .catch(function (err) {
    console.log(err);
  });

Error i am getting is

{ Error: No access token
    at AuthClient.getAccessToken.then.tokenInfo (E:\Development\node-scripts\node_modules\fuel-rest\lib\fuel-rest.js:88:18)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
  res:
   { error: 'unsupported_grant_type',
     error_description: 'Use "authorization_code" or "refresh_token" or "client_credentials" or "urn:ietf:params:oauth:grant-type:jwt-bearer" as the grant_type.',
     error_uri: 'https://developer.salesforce.com/docs' } }

I hope i am initializing the client correctly for my use case.

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.