I am doing a POST request to auth api with a username and password and expecting a token in the response.
fetch('https://auth.entranceplus.in/auth', {
credentials: 'omit',
method: 'POST',
mode: 'cors',
body: JSON.stringify({
"username": this.userName.value,
"password": this.password.value
}),
headers: new Headers({
'Access-Control-Allow-Origin': '*',
'Accept': 'application/json',
'Content-Type': 'application/json',
'Data-Type': "json"
})
}).then(function (response) {
if (response.status === 200) {
return response.json();
} else if (response.status === 503) {
this.setErrorMessage('Failed to check-out license');
} else {
this.setErrorMessage('Incorrect Username or Password');
}
}.bind(this)).then(json => {
localStorage.setItem('username', this.userName.value);
localStorage.setItem('accesstoken', json.access_token);
});
As you can see in the image Request URL is http://localhost:3000/?username=dfbfdjhgfk&password=76895jfjg
My question is why the request not getting posted to https://auth.entranceplus.in/auth
Related
I am trying to create a new session with axios following this documentation:
https://www.traccar.org/api-reference/#tag/Session/paths/~1session/post
This is my code, I have really tried everything without results
const sessionurl = 'http://31.220.52.187:8082/api/session';
const params = new URLSearchParams();
params.append('email', 'admin');
params.append('password', 'admin');
const config = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}
axios
.post(
sessionurl,
{
withCredentials: true,
headers: {
Accept: 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
'Access-Control-Allow-Origin': '*',
},
},
{
params
},
)
.then(function (response) {
console.log('Authenticated');
})
.catch(function (error) {
console.log('Error on Authentication');
});
It should be something like this:
const params = new URLSearchParams();
params.append('email', 'admin');
params.append('password', 'admin');
axios.post(sessionUrl, params);
You might need to also add a header.
I am implementing the Search function using spotify api.
However, if you request get to api now, 400 will be returned.
I want you to help me with this.
axios({
headers: {
"Authorization": `Bearer ${token}`
},
method: 'GET',
url: 'https://api.spotify.com/v1/search',
qs: {
q: value,
type: 'album',
},
}).then((res) => {
console.log(res);
}).catch(err => {
console.log(err);
})
const options = {
method: 'GET',
url: `https://api.spotify.com/v1/search?q=${value}&type=album`,
headers: {
'Authorization': `Bearer ${token}`,
"Accept": "application/json",
"Content-Type": "application/json",
}
}
axios(options).then((res)=>console.log(res))
.catch(err=>console.error(err))
I am trying to make an axios get request to this endpoint, but I am keep getting this error " [Error: Request failed with status code 400]".
clikk = () => {
console.log('saasdasdl');
var user = 'reflect-user';
var pass = 'user1Pass';
let dta = JSON.stringify({
username: 'test.admin',
password: 'password',
emailAddress: 'test#gmai.com',
});
const headers = {
'Content-Type': 'application/json',
Authorization: 'Basic ctesmtVmbGVjdC11c2VyOnVzZXIxUGFzcw==',
'Access-Control-Allow-Origin': '*',
accept: 'application/json',
};
// var bytes = utf8.encode(user + ':' + pass);
// var authorizationBasic = base64.encode(bytes);
axios({
method: 'get',
url: 'http://IpOfServer:8080/api/v1/user/getUser?all=true',
headers: headers,
data: qs.parse({
username: 'test.admin',
password: 'password',
emailAddress: 'test#gmai.com',
}),
})
.then((res) => {
//const nameList = res.data;
//this.setState({nameList});
console.log(res);
})
.catch((error) => console.log(error));
};
However same request is working in POSTMAN so API may not be involved ish? I've also tried to AXIOS example provided by POSTMAN but I am getting the same error.
var data = JSON.stringify({"username":"test.admin","password":"password","emailAddress":"test6#gmai.com"});
var config = {
method: 'get',
url: 'http://IpOfServer:8080/api/v1/user/getUser?all=true',
headers: {
'Authorization': 'Basic cmVmbGVjdC11c2VyOnVzZXIxUGFzcw==',
'Content-Type': 'application/json'
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
Thank you.
I am getting network error while doing axios.post request.
axios.post({
method:'POST',
url:'http://xxx.xxx.xxx.xxx:6310',
withCredentials: true,
auth: { username: 'username',
password: 'password'},
headers: {'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'},
data :{"jsonrpc":"1.0", "method":"liststreams","params":[]}
}).then(function(response) {
console.log('res ------- ',response)
}).catch(function(error) {
console.log('error =',error)
})
Thanks,
I try update the current user email but the Auth0 API response returns 403 error with this payload:
{
"statusCode":403,
"error":"Forbidden",
"message":"You cannot update the following fields: email",
"errorCode":"insufficient_scope"
}
But I pass the scope when I instantiate the lock.
this.lock = new Auth0Lock(clientId, domain, {
auth: {
redirectUrl: 'http://localhost:3000/login',
responseType: 'token',
params: {
scope: 'openid email user_metadata app_metadata picture update:users'
}
},
My script to send the PATCH:
updateProfile(userId, data){
const headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + this.getToken() //setting authorization header
}
// making the PATCH http request to auth0 api
return fetch(`https://${this.domain}/api/v2/users/${userId}`, {
method: 'PATCH',
headers: headers,
body: JSON.stringify(data)
})
.then(response => response.json())
.then(newProfile => {
this.setProfile(newProfile)
}) //updating current profile
}
Any ideas?