0

Authorization for Client Credentials Flow

Hi I have read other Questions or not working properly the current response is 400 (Bad Request) what I had

The following is my code (Authorization has converted Base64)

const testAuth = () => {
return () => {
    Axios({
        url: 'https://accounts.spotify.com/api/token',
        method: 'post',
        params: {
            grant_type: 'client_credentials'
        },
        headers: {
            'Authorization': 'Basic MWM3NGFkOGQyNDgzNDI0Y2E4NGVmYWRlNzI1MzI5YzE6MDBmMGFmNDE1ZTZhNDgxOThiOWRlYzFmNmE2NTk5NDQ=',
            'Content-Type': 'application/x-www-form-urlencoded'
        },
    }).then((respond) => {
        console.log(respond);
    }).catch((error) => {
        console.log(error);
    });
};

But things that are working with returned tokens as well as using spotify wep api normally by using Postman to send out the same content . Is my code uncorrent or is there any problem? (Authorization in Postman is the same as above)


Thank everyone, I just realized is an error of cors. However, there are many ways for trying still can't solve the 400. For eaxmple: Chrome extension access-control-expose-headers

Preflighted Requests image 400 Respond image

Jiang Wen
  • 57
  • 8
  • Hi there - I ran this code on my computer and it gave me an access token with no trouble. What exactly are you struggling with? PS - you should not share your client id/secret, even if encoded. It's called a secret for a reason! – arirawr Jan 30 '18 at 13:35
  • Run without the extra first two lines, by the way, as I'm not sure why they were necessary. – arirawr Jan 30 '18 at 13:38
  • Thanks for your reminds. Don't worry about that client id/secret is just individual work, no one needs to use it and I'll reset secret again. For the point, should I delet the two code as following`const testAuth = () => { return () => {`to ran successfully? – Jiang Wen Jan 31 '18 at 04:39
  • Yes, delete those two lines and the last line and it worked for me. – arirawr Jan 31 '18 at 09:25
  • Thank you, I just realized is an error of cors. Because Iran it on localhost, still haveing some troubles. Please give me other suggestions. – Jiang Wen Feb 01 '18 at 14:47
  • There are a ton of Stack Overflow answers about CORS. I highly recommend searching for and reading those. – arirawr Feb 01 '18 at 14:56
  • Possible duplicate of [Why does my JavaScript get a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error when Postman does not?](https://stackoverflow.com/questions/20035101/why-does-my-javascript-get-a-no-access-control-allow-origin-header-is-present) – arirawr Feb 01 '18 at 14:57

0 Answers0