我成功获取了令牌,但是我不知道其他请求中有什么问题,有人可以帮我吗?
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)});
})
此错误是因为您没有使用正确的toke,here you can find more info,