adamprocter
adamprocter

Reputation: 856

axios header Authorization using vue.js

I am trying to use a header token with axios. However I am presented with a CORS error as I am clearly not passing over the token correctly (moving to a not authorized feed works)

Here is my http-common.js file

   const token = `08E1B4C220E671AC6A48`
// my user app token from micro.blog 08E1B4C220E671AC6A48
export const HTTP = axios.create({
  //  baseURL: 'https://micro.blog/feeds/adamprocter.json'
  baseURL: 'https://micro.blog',
  headers: {
    Authorization: `Bearer ${token}`
      }
    })

and here is my Timeline.vue component

import { HTTP } from '@/http-common'

export default {
  components: {
    MicroPosts
  },
  data() {
    return {
      posts: []
    }
  },
  created() {
// no auth get = HTTP.get('')
    HTTP.get('/account/verify')
      .then(response => {
        //console.log(response.data)
        this.posts = response.data.items
      })
      .catch(error => {
        console.log('caught error' + error.response)
      })
  }
}

The URL is correct but the token is failing (I believe) POST /account/verify — Accepts an app token (which I have set up) and returns an auth token and other details.

This is the API documentation which is a little sparse but

http://help.micro.blog/2017/api-json/

http://help.micro.blog/2018/api-authentication/

I am sure it is something obvious, any help much appreciated.

Upvotes: 0

Views: 244

Answers (1)

Eric Guan
Eric Guan

Reputation: 15982

The documentation says /account/verify accepts POST. You are sending a GET.

Upvotes: 0

Related Questions