Search code examples
vue.jsvue-resource

Endpoint keep returning 401


The following works just fine. I get an access token which I can use in subsequent requests.

curl localhost:8080/oauth/token --user html5:password -d grant_type=password -d username=name -d password=pass

However when I try to du the same using vue-resource I get 401.

const options = {
  headers: {
    Authorization: 'Basic ' + window.btoa('html5:password')
  },
  params: {
    'client_id': 'html5',
    'client_secret': 'password',
    'grant_type': 'password',
    'username': 'name',
    'password': 'pass'
  }
}

context.$http.post(LOGIN_URL, options).then((response) => {
  localStorage.setItem(this.storageKey, response.access_token)
  // TODO: Check 200 ok
  this.user.authenticated = true
  if (redirect) {
    Router.go(redirect)
  }
})

Any clue about what I'm doing wrong?


Solution

  • This ended up being a CORS issue which went away when both client and server is served from the same doamin.