1

Using javascript axios am trying to fetch a token from dart's aqueduct. https://aqueduct.io/docs/auth/controllers/ aqueduct uses oauth2 specification on the backend, and it has sample code for fetching on dart. Dart code is working:

var clientID = "com.app.demo";
var clientSecret = "mySecret";
var body = "username=bob@stablekernel.com&password=foobar&grant_type=password";
var clientCredentials = Base64Encoder().convert("$clientID:$clientSecret".codeUnits);

var response = await http.post(
  "https://stablekernel.com/auth/token",
  headers: {
    "Content-Type": "application/x-www-form-urlencoded",
    "Authorization": "Basic $clientCredentials"
  },
  body: body);

being said, am trying with axios for my vuejs app. here is the code am trying:

const url = 'http://localhost:8888/auth/token';
    const encodedSecret = Buffer.from('com.local.test:').toString('base64')
    return  Axios({
        method: 'POST',
        url,
        headers: {
            "Content-Type": "application/x-www-form-urlencoded",
            "Authorization": `Basic ${encodedSecret}`
        },
        data: `username=${username}&password=${password}&grant_type=password`
    }).then((response)=>{
        console.log(response)
     })
        .catch((error) => {
            console.log(' error:', error)
        });

am always getting bad request error code 400. what am i doing wrong? how do i fetch token? refresh token is also something will have to worry about later on.

7skies
  • 167
  • 4
  • 17
  • i'm not familiar with axios.. yet though it's recommended to test your endpoints on postman first to make sure everything is working fine – Amr Ahmed Apr 22 '20 at 10:59

0 Answers0