带有承载令牌的POST请求中的错误401

问题描述 投票:0回答:1

我成功获取了令牌,但是我不知道其他请求中有什么问题,有人可以帮我吗?

  const username = <username>
  const password = <password>
  const encode = Buffer.from(`${username}:${password}`, 'utf8').toString('base64')

  const requestOptions = {
      method: 'POST',
      headers: {  'Content-Type': 'application/x-www-form-urlencoded',
                  'Authorization': `Basic ${encode}`,
              },
  };

  fetch("https://<user>.us-east-1.amazoncognito.com/oauth2/token?grant_type=client_credentials", requestOptions)
  .then(response => { return response.json() })
  .then(data => { 
    const requestOptions2 = {
      method: 'POST',
      mode: 'no-cors',
      headers: {  'Content-Type': 'application/json',
                  'Authorization': `Bearer ${data.access_token}`,
              },
      body: '{"username":"Crhistian", "password":"123","user_id":"[email protected]"}'
    };
    fetch('https://<user>.execute-api.sa-east-1.amazonaws.com/v1/register', requestOptions2)
    .then(response => {console.log(response)});
  })
javascript http access-token basic-authentication http-status-code-401
1个回答
0
投票

此错误是因为您没有使用正确的toke,here you can find more info

© www.soinside.com 2019 - 2024. All rights reserved.