Skip to content

签名成功,并且请求时也有附带 token,但是后台一直报No authorization token was found #63

@cuevven

Description

@cuevven
// config/config.default.js
    jwt: {
      secret: 'Great4-M',
      enable: true,
      ignore: '/api/user/access/login',
    }
// app/router.js
  const { router, controller, middleware } = app;
  const jwt = middleware.jwt(app.config.jwt);
  router.get('/api/user', jwt, controller.user.index)
// Request Headers
GET /api/user?page=1&limit=20 HTTP/1.1
Host: 127.0.0.1:7001
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: application/json, text/plain, */*
Sec-Fetch-Dest: empty
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7Il9pZCI6IjVlODYwNDk4ZjZmOTU4Nzk5MmU2NzdhMiJ9LCJleHAiOjE1ODY3MDQyMjgsImlhdCI6MTU4NjA5OTQyOH0.AX03Jfv5g9cAVv9apBb3gpNlY-lHMjkChmhG6TNNmJA
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36
Origin: http://localhost:9528
Sec-Fetch-Site: cross-site
Sec-Fetch-Mode: cors
Referer: http://localhost:9528/dashboard
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,zh-TW;q=0.6
// server log
2020-04-05 23:20:26,620 WARN 78099 [-/127.0.0.1/-/0ms GET /api/user?page=1&limit=20] nodejs.UnauthorizedError: No authorization token was found
    at middleware (/node_modules/koa-jwt2/lib/index.js:89:15)
    at fn (/node_modules/egg-core/lib/loader/mixin/middleware.js:112:12)
    at dispatch (/node_modules/koa/node_modules/koa-compose/index.js:42:32)
    at /node_modules/egg-development/app/middleware/egg_loader_trace.js:9:56
    at dispatch (/node_modules/koa/node_modules/koa-compose/index.js:42:32)
    at i18n (/node_modules/egg-i18n/app/middleware/i18n.js:13:12)
    at dispatch (/node_modules/koa/node_modules/koa-compose/index.js:42:32)
    at dispatch (/node_modules/egg-security/node_modules/koa-compose/index.js:42:32)
    at dta (/node_modules/egg-security/lib/middlewares/dta.js:12:12)
    at dispatch (/node_modules/egg-security/node_modules/koa-compose/index.js:42:32)
    at xframe (/node_modules/egg-security/lib/middlewares/xframe.js:7:11)
    at dispatch (/node_modules/egg-security/node_modules/koa-compose/index.js:42:32)
    at xssProtection (/node_modules/egg-security/lib/middlewares/xssProtection.js:7:11)
    at dispatch (/node_modules/egg-security/node_modules/koa-compose/index.js:42:32)
    at nosniff (/node_modules/egg-security/lib/middlewares/nosniff.js:8:11)
    at dispatch (/node_modules/egg-security/node_modules/koa-compose/index.js:42:32)
name: "UnauthorizedError"
message: "No authorization token was found"
code: "credentials_required"
status: 401
inner: {"message":"No authorization token was found"}
pid: 78099

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions