Question Details

Answered
What is the proper way to make the API request to verify the access token?

I keep getting the "error_description": "The access token malformed". Not sure how to fix this. Any help would be much appreciated. Have tried the follwoing two methods to make the request:

Method 1:

<!-- Use the below function to create vrifyTokenOptions object -->

function generateLineApiRequest(apiEndpoint, lineAccessToken) { return { url: apiEndpoint, headers: { 'Authorization': Bearer ${lineAccessToken}, }, json: true, }; } // Send request to LINE server for access token verification const verifyTokenOptions = generateLineApiRequest('https://api.line.me/oauth2/v2.1/verify', lineAccessToken); return request(verifyTokenOptions) .then(response => {...

Method 2

<!-- No need for headers -->

var apiEndpoint = 'https://api.line.me/oauth2/v2.1/verify?access_token=' + lineAccessToken; return request({ method: 'GET', uri: apiEndpoint, json: true }).then((response) => {...

0
Profile picture
Todd

Answers

1
Profile picture
Gildas
Posted: 3 months ago

You cannot actually verify the access_token, you can only use it or generate a new one.

So, basically, you make your messaging_api calls like normal and if you get a 401 Unauthorized, you know you need to generate a new access_token.

Something like:

  response = await this.post('https://api.line.me/v2/oauth/accessToken', {
      grant_type:    'client_credentials',
      client_id:     channel_id,
      client_secret: channel_secret,
    },
    {
      content_type:  'form',
      authorization: 'oauth',
    })
		// response = { "access_token": "XXXXXX", "expires_in": 2592000, "token_type": "Bearer" }
Are you sure? question.vm