Попытка получить токен доступа из Restful API (Axios с React-native), однако только для получения errormessage:
"error": "unauthorized", "error_description": "Полная аутентификациятребуется доступ к этому ресурсу "
function accessToken(){
axios({
method: 'post',
url: 'myurl',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
//'Access-Control-Allow-Origin': '*',
},
data: {
client_id: 'myid',
client_secret: 'mysecret',
grant_type: 'client_credentials'
},
})
.then(function(res){
console.log(res);
console.log(res.data);
})
.catch(function(err) {
console.log(err);
console.log(err.response.data);
console.log(err.response.status);
console.log(err.response.headers);
console.log(err.request);
console.log(err.message);
console.log(err.config);
});
}
Object {
"error": "unauthorized",
"error_description": "Full authentication is required to access this resource",
}
401
Я попытался получить токен доступа от Restful API, созданного из Oauth.Однако я получаю только ошибку 401 с
«Для доступа к этому ресурсу требуется полная аутентификация».
Я уже пытался
add 'Access-Control-Allow-Origin': '*' in headers,
base64 encode id and pw,
add withCredential : true and false,
create instance with axios.create.
Вот пример использования API.другие функции, которые я сделал с Axios в React-native, работают хорошо, однако не работает только эта функция, которая должна получить accesstoken.
curl -X POST \
http://api_domain:port/oauth/token \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'client_id=00002&client_secret=gateway-api-secret&grant_type=client_credentials'
Заранее спасибо.