OAuth 2 client credentials token received in postman but not in serverWhat are Bearer Tokens and token_type in OAuth 2?How to validate an OAuth 2.0 access token for a resource server?Sending JWT token in the headers with Postmannodejs oauth2 token regeneration help neededOAuth client credentials conceptes6 mongoose nested findById promiseCORS issue making AJAX request from React app > Node server > redirect to Google OAuth2 authOAuth2 (unsupported_grant_type) Invalid grant_type: client_credentialsWait for data from external API before making POST requestHow to send github OAuth data to client?

15% tax on $7.5k earnings. Is that right?

Does Doodling or Improvising on the Piano Have Any Benefits?

What is the English pronunciation of "pain au chocolat"?

Why does Carol not get rid of the Kree symbol on her suit when she changes its colours?

A variation to the phrase "hanging over my shoulders"

A Trivial Diagnosis

Why should universal income be universal?

What does Apple's new App Store requirement mean

Creating two special characters

US tourist/student visa

What's the name of the logical fallacy where a debater extends a statement far beyond the original statement to make it true?

How could a planet have erratic days?

Is there a RAID 0 Equivalent for RAM?

Shouldn’t conservatives embrace universal basic income?

Which Article Helped Get Rid of Technobabble in RPGs?

Has the laser at Magurele, Romania reached a tenth of the Sun's power?

What (the heck) is a Super Worm Equinox Moon?

What is Cash Advance APR?

Does "he squandered his car on drink" sound natural?

Is there a nicer/politer/more positive alternative for "negates"?

Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?

What is the difference between lands and mana?

Why is the Sun approximated as a black body at ~ 5800 K?

Multiplicative persistence



OAuth 2 client credentials token received in postman but not in server


What are Bearer Tokens and token_type in OAuth 2?How to validate an OAuth 2.0 access token for a resource server?Sending JWT token in the headers with Postmannodejs oauth2 token regeneration help neededOAuth client credentials conceptes6 mongoose nested findById promiseCORS issue making AJAX request from React app > Node server > redirect to Google OAuth2 authOAuth2 (unsupported_grant_type) Invalid grant_type: client_credentialsWait for data from external API before making POST requestHow to send github OAuth data to client?













0















anyone can help me as I'm stuck to get an tokken from:
https://www.parcel2go.com/api/docs/articles/intro.html



Example Token Request:



POST /auth/connect/token HTTP/1.1
Host: sandbox.parcel2go.com
User-Agent: insomnia/5.14.6
Content-Type: application/x-www-form-urlencoded
Accept: */*
grant_type=client_credentials
&scope=public-api%20payment
&client_id=<client_id>
&client_secret=<client_secret>


Here is a photo from postman where all is working fine:



postman screen shoot
I have 2 solutions:



Solution number 1:



Here is a server:



const express = require("express");
const app = express();

const ClientOAuth2 = require("client-oauth2");
const p2gAuth = new ClientOAuth2(
clientId: "52bec26d025a4b8db2248a90da1e455a:testing",
clientSecret: "testing123",
accessTokenUri: "https://sandbox.parcel2go.com/auth/connect/token",
scopes: ["public-api", "payment"]
);

app.get("/api/getToken", (req, res) =>
p2gAuth.credentials.getToken().then(function(user)
console.log(user); //=> accessToken: '...', tokenType: 'bearer', ...
);
);

app.listen(3001, () =>
console.log("Express server is running on localhost:3001")
);


I getting response:



(node:22703) UnhandledPromiseRejectionWarning: Error: Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method).
at getAuthError (/Users/mario/Documents/VS/mario-p2g/node_modules/client-oauth2/src/client-oauth2.js:121:15)
at /Users/Mario/Documents/VS/mario-p2g/node_modules/client-oauth2/src/client-oauth2.js:269:21
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:22703) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:22703) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


Solution number 2:



Would someone explain me what to do and the best I would like to know how to use this in fetch request, what is wrong with that code:



const express = require("express");
const app = express();
const fetch = require("node-fetch");

app.get("/api/getToken", (req, res) =>
fetch("https://sandbox.parcel2go.com/auth/connect/token",
method: "POST",
headers:
"User-Agent": "insomnia/5.14.6",
"Content-Type": "application/x-www-form-urlencoded",
Accept: "*/*"
,
body:
grant_type: "client_credentials",
client_id: "52bec26d025a4b8db2248a90da1e455a:testing",
client_secret: "testing123",
scope: ["public-api", "payment"]

)
.then(response => response.json())
.then(body =>
if (body)
res.json(body);
else
res.json( error: "no body after respond" );

)
.catch(error =>
res.json(error);
console.log("Server failed to return data: " + error);
);
);

app.listen(3001, () =>
console.log("Express server is running on localhost:3001")
);









share|improve this question







New contributor




Mario is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    0















    anyone can help me as I'm stuck to get an tokken from:
    https://www.parcel2go.com/api/docs/articles/intro.html



    Example Token Request:



    POST /auth/connect/token HTTP/1.1
    Host: sandbox.parcel2go.com
    User-Agent: insomnia/5.14.6
    Content-Type: application/x-www-form-urlencoded
    Accept: */*
    grant_type=client_credentials
    &scope=public-api%20payment
    &client_id=<client_id>
    &client_secret=<client_secret>


    Here is a photo from postman where all is working fine:



    postman screen shoot
    I have 2 solutions:



    Solution number 1:



    Here is a server:



    const express = require("express");
    const app = express();

    const ClientOAuth2 = require("client-oauth2");
    const p2gAuth = new ClientOAuth2(
    clientId: "52bec26d025a4b8db2248a90da1e455a:testing",
    clientSecret: "testing123",
    accessTokenUri: "https://sandbox.parcel2go.com/auth/connect/token",
    scopes: ["public-api", "payment"]
    );

    app.get("/api/getToken", (req, res) =>
    p2gAuth.credentials.getToken().then(function(user)
    console.log(user); //=> accessToken: '...', tokenType: 'bearer', ...
    );
    );

    app.listen(3001, () =>
    console.log("Express server is running on localhost:3001")
    );


    I getting response:



    (node:22703) UnhandledPromiseRejectionWarning: Error: Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method).
    at getAuthError (/Users/mario/Documents/VS/mario-p2g/node_modules/client-oauth2/src/client-oauth2.js:121:15)
    at /Users/Mario/Documents/VS/mario-p2g/node_modules/client-oauth2/src/client-oauth2.js:269:21
    at process._tickCallback (internal/process/next_tick.js:68:7)
    (node:22703) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
    (node:22703) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


    Solution number 2:



    Would someone explain me what to do and the best I would like to know how to use this in fetch request, what is wrong with that code:



    const express = require("express");
    const app = express();
    const fetch = require("node-fetch");

    app.get("/api/getToken", (req, res) =>
    fetch("https://sandbox.parcel2go.com/auth/connect/token",
    method: "POST",
    headers:
    "User-Agent": "insomnia/5.14.6",
    "Content-Type": "application/x-www-form-urlencoded",
    Accept: "*/*"
    ,
    body:
    grant_type: "client_credentials",
    client_id: "52bec26d025a4b8db2248a90da1e455a:testing",
    client_secret: "testing123",
    scope: ["public-api", "payment"]

    )
    .then(response => response.json())
    .then(body =>
    if (body)
    res.json(body);
    else
    res.json( error: "no body after respond" );

    )
    .catch(error =>
    res.json(error);
    console.log("Server failed to return data: " + error);
    );
    );

    app.listen(3001, () =>
    console.log("Express server is running on localhost:3001")
    );









    share|improve this question







    New contributor




    Mario is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      0












      0








      0








      anyone can help me as I'm stuck to get an tokken from:
      https://www.parcel2go.com/api/docs/articles/intro.html



      Example Token Request:



      POST /auth/connect/token HTTP/1.1
      Host: sandbox.parcel2go.com
      User-Agent: insomnia/5.14.6
      Content-Type: application/x-www-form-urlencoded
      Accept: */*
      grant_type=client_credentials
      &scope=public-api%20payment
      &client_id=<client_id>
      &client_secret=<client_secret>


      Here is a photo from postman where all is working fine:



      postman screen shoot
      I have 2 solutions:



      Solution number 1:



      Here is a server:



      const express = require("express");
      const app = express();

      const ClientOAuth2 = require("client-oauth2");
      const p2gAuth = new ClientOAuth2(
      clientId: "52bec26d025a4b8db2248a90da1e455a:testing",
      clientSecret: "testing123",
      accessTokenUri: "https://sandbox.parcel2go.com/auth/connect/token",
      scopes: ["public-api", "payment"]
      );

      app.get("/api/getToken", (req, res) =>
      p2gAuth.credentials.getToken().then(function(user)
      console.log(user); //=> accessToken: '...', tokenType: 'bearer', ...
      );
      );

      app.listen(3001, () =>
      console.log("Express server is running on localhost:3001")
      );


      I getting response:



      (node:22703) UnhandledPromiseRejectionWarning: Error: Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method).
      at getAuthError (/Users/mario/Documents/VS/mario-p2g/node_modules/client-oauth2/src/client-oauth2.js:121:15)
      at /Users/Mario/Documents/VS/mario-p2g/node_modules/client-oauth2/src/client-oauth2.js:269:21
      at process._tickCallback (internal/process/next_tick.js:68:7)
      (node:22703) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
      (node:22703) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


      Solution number 2:



      Would someone explain me what to do and the best I would like to know how to use this in fetch request, what is wrong with that code:



      const express = require("express");
      const app = express();
      const fetch = require("node-fetch");

      app.get("/api/getToken", (req, res) =>
      fetch("https://sandbox.parcel2go.com/auth/connect/token",
      method: "POST",
      headers:
      "User-Agent": "insomnia/5.14.6",
      "Content-Type": "application/x-www-form-urlencoded",
      Accept: "*/*"
      ,
      body:
      grant_type: "client_credentials",
      client_id: "52bec26d025a4b8db2248a90da1e455a:testing",
      client_secret: "testing123",
      scope: ["public-api", "payment"]

      )
      .then(response => response.json())
      .then(body =>
      if (body)
      res.json(body);
      else
      res.json( error: "no body after respond" );

      )
      .catch(error =>
      res.json(error);
      console.log("Server failed to return data: " + error);
      );
      );

      app.listen(3001, () =>
      console.log("Express server is running on localhost:3001")
      );









      share|improve this question







      New contributor




      Mario is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      anyone can help me as I'm stuck to get an tokken from:
      https://www.parcel2go.com/api/docs/articles/intro.html



      Example Token Request:



      POST /auth/connect/token HTTP/1.1
      Host: sandbox.parcel2go.com
      User-Agent: insomnia/5.14.6
      Content-Type: application/x-www-form-urlencoded
      Accept: */*
      grant_type=client_credentials
      &scope=public-api%20payment
      &client_id=<client_id>
      &client_secret=<client_secret>


      Here is a photo from postman where all is working fine:



      postman screen shoot
      I have 2 solutions:



      Solution number 1:



      Here is a server:



      const express = require("express");
      const app = express();

      const ClientOAuth2 = require("client-oauth2");
      const p2gAuth = new ClientOAuth2(
      clientId: "52bec26d025a4b8db2248a90da1e455a:testing",
      clientSecret: "testing123",
      accessTokenUri: "https://sandbox.parcel2go.com/auth/connect/token",
      scopes: ["public-api", "payment"]
      );

      app.get("/api/getToken", (req, res) =>
      p2gAuth.credentials.getToken().then(function(user)
      console.log(user); //=> accessToken: '...', tokenType: 'bearer', ...
      );
      );

      app.listen(3001, () =>
      console.log("Express server is running on localhost:3001")
      );


      I getting response:



      (node:22703) UnhandledPromiseRejectionWarning: Error: Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method).
      at getAuthError (/Users/mario/Documents/VS/mario-p2g/node_modules/client-oauth2/src/client-oauth2.js:121:15)
      at /Users/Mario/Documents/VS/mario-p2g/node_modules/client-oauth2/src/client-oauth2.js:269:21
      at process._tickCallback (internal/process/next_tick.js:68:7)
      (node:22703) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
      (node:22703) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


      Solution number 2:



      Would someone explain me what to do and the best I would like to know how to use this in fetch request, what is wrong with that code:



      const express = require("express");
      const app = express();
      const fetch = require("node-fetch");

      app.get("/api/getToken", (req, res) =>
      fetch("https://sandbox.parcel2go.com/auth/connect/token",
      method: "POST",
      headers:
      "User-Agent": "insomnia/5.14.6",
      "Content-Type": "application/x-www-form-urlencoded",
      Accept: "*/*"
      ,
      body:
      grant_type: "client_credentials",
      client_id: "52bec26d025a4b8db2248a90da1e455a:testing",
      client_secret: "testing123",
      scope: ["public-api", "payment"]

      )
      .then(response => response.json())
      .then(body =>
      if (body)
      res.json(body);
      else
      res.json( error: "no body after respond" );

      )
      .catch(error =>
      res.json(error);
      console.log("Server failed to return data: " + error);
      );
      );

      app.listen(3001, () =>
      console.log("Express server is running on localhost:3001")
      );






      node.js express oauth-2.0






      share|improve this question







      New contributor




      Mario is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Mario is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Mario is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 13 hours ago









      MarioMario

      362




      362




      New contributor




      Mario is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Mario is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Mario is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          Mario is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280142%2foauth-2-client-credentials-token-received-in-postman-but-not-in-server%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          Mario is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          Mario is a new contributor. Be nice, and check out our Code of Conduct.












          Mario is a new contributor. Be nice, and check out our Code of Conduct.











          Mario is a new contributor. Be nice, and check out our Code of Conduct.














          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid …


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280142%2foauth-2-client-credentials-token-received-in-postman-but-not-in-server%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

          Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?