Топор ios достать жетон из акведука дротика - PullRequest
1 голос
/ 21 апреля 2020

Используя javascript axios, я пытаюсь получить токен из дротика aqueduct. https://aqueduct.io/docs/auth/controllers/ акведук использует спецификацию oauth2 на бэкэнде, и у него есть пример кода для извлечения на дротике. Код дротика работает:

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);

как говорится, пытаюсь с топором ios для моего приложения vuejs. Вот код, который я пытаюсь:

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)
        });

я всегда получаю bad request код ошибки 400. Что я делаю неправильно? как мне получить токен? refre sh token - это еще кое-что, о чем нужно будет беспокоиться позже.

...