发表文章

[Javascript] 可以通过中间件对令牌进行身份验证吗? "Possible to authenticate with token via middleware?"[adonis-framework]

dunkdunk 6月前 17

不是问题, 而是授权问题:

阅读完中间件的文档后, 我很好奇是否有一种方法可以从 cookie 中读取身份验证令牌并将其传递给身份验证中间件 (使用 API 方案或 JWT 方案)。

我的全局中间件看起来像这样:

'use strict'

class TokenGetter {

  * handle (request, response, next) {
    // Read the token from cookie and decorate the request
    const token = request.cookie('token')
    request.token = token

    // Pass it along
    yield next
  }

}

module.exports = TokenGetter

是否可以用这样的方法对使用内置身份验证中间件的用户进行身份验证?

原文:

Not an issue, but an authorization question:

After reading through the docs on middleware, I'm curious if there is a way to read an authentication token from a cookie and pass it to the authentication middleware (using either the API scheme or JWT scheme).

My global middleware looks like this:

'use strict'

class TokenGetter {

  * handle (request, response, next) {
    // Read the token from cookie and decorate the request
    const token = request.cookie('token')
    request.token = token

    // Pass it along
    yield next
  }

}

module.exports = TokenGetter

Is it possible to authenticate users with the built-in authentication middleware with a method like this?

相关推荐
最新评论 (4)
thetutlage 6月前
1

您可以通过中间件设置授权报头

原文:

You can set the Authorization header via middleware

dunkdunk 6月前
2

对不起, 如果这是一个愚蠢的问题, 但我如何设置标题与阿多尼斯?读完文档后, 我发现读取标头值很容易, 但对于如何设置它们却感到困惑。

原文:

Sorry if this is a silly question, but how would I set headers with Adonis? After reading the docs, I see that it is very easy to read header values, but am confused on how to set them.

thetutlage 6月前
3

你可以说跟随在一个中间件里面

request.request.headers['authorization'] = 'your token'

请确保在身份验证中间件之前调用上述中间件并在此处定义它https://github.com/adonisjs/adonis-app/blob/develop/app/Http/kernel.js#L32

原文:

You can say following inside a middleware

request.request.headers['authorization'] = 'your token'

Make sure to call the above middleware before the authentication middleware and define it here https://github.com/adonisjs/adonis-app/blob/develop/app/Http/kernel.js#L32

dunkdunk 6月前
4

明白了。非常感谢你的帮助。

原文:

Got it. Thanks so much for your help with this.

返回
发表文章
dunkdunk
文章数
1
评论数
2
注册排名
93086