Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Scheme type api is not working, it showing error "Missing or Invalid Token" #43

Open
zeeshanyshaikh opened this issue Jul 4, 2019 · 0 comments
Labels

Comments

@zeeshanyshaikh
Copy link

My auth.js looks like

'use strict'

/** @type {import('@adonisjs/framework/src/Env')} */
const Env = use('Env')

module.exports = {
  /*
  |--------------------------------------------------------------------------
  | Authenticator
  |--------------------------------------------------------------------------
  |
  | Authentication is a combination of serializer and scheme with extra
  | config to define on how to authenticate a user.
  |
  | Available Schemes - basic, session, jwt, api
  | Available Serializers - lucid, database
  |
  */
  authenticator: 'api',

  /*
  |--------------------------------------------------------------------------
  | Session
  |--------------------------------------------------------------------------
  |
  | Session authenticator makes use of sessions to authenticate a user.
  | Session authentication is always persistent.
  |
  */
  session: {
    serializer: 'LucidMongo',
    model: 'App/Models/User',
    scheme: 'session',
    uid: 'email',
    password: 'password'
  },

  /*
  |--------------------------------------------------------------------------
  | Basic Auth
  |--------------------------------------------------------------------------
  |
  | The basic auth authenticator uses basic auth header to authenticate a
  | user.
  |
  | NOTE:
  | This scheme is not persistent and users are supposed to pass
  | login credentials on each request.
  |
  */
  basic: {
    serializer: 'LucidMongo',
    model: 'App/Models/User',
    scheme: 'basic',
    uid: 'email',
    password: 'password'
  },

  /*
  |--------------------------------------------------------------------------
  | Jwt
  |--------------------------------------------------------------------------
  |
  | The jwt authenticator works by passing a jwt token on each HTTP request
  | via HTTP `Authorization` header.
  |
  */
  jwt: {
    serializer: 'LucidMongo',
    model: 'App/Models/User',
    scheme: 'jwt',
    uid: 'email',
    password: 'password',
    expiry: '1m',
    options: {
      secret: Env.get('APP_KEY')
    }
  },

  /*
  |--------------------------------------------------------------------------
  | Api
  |--------------------------------------------------------------------------
  |
  | The Api scheme makes use of API personal tokens to authenticate a user.
  |
  */
  api: {
    serializer: 'LucidMongo',
    scheme: 'api',
    model: 'App/Models/User',
    uid: 'email',
    password: 'password',
    expiry: '30d',
  },
}

My logout function uses auth middleware.

Route.post('/api/v1/logout', 'AuthController.logout').as('logout').middleware('auth')

Now when i request this from Postman tool am getting error as "E_INVALID_API_TOKEN: The api token is missing or invalid"

Am using Mongo db, and i have generated token using attempt method while login

await auth.attempt(uid, password)

Am also passing bearer token in postman which i got from attempt method.

"token": {
     "type": "bearer",
     "token": "0a957d5a02a62954b38e8b1e848462d2M2BDMqc72R0z3oRsUCkqyoUTknz7V/Q7AJ6OOVcU1crgOAz8uvQNgUUAzaIadSNH"
            }

Still am getting same error that token is missing...please help me understand what is wrong here. Thanks.

@zeeshanyshaikh zeeshanyshaikh changed the title Schema type api is not working, it showing error "Missing or Invalid Token" Scheme type api is not working, it showing error "Missing or Invalid Token" Jul 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant