【问题标题】:Why app.logout() not calls the remove method of the /authentication service on the Feathers server?为什么 app.logout() 不调用 Feathers 服务器上 /authentication 服务的 remove 方法?
【发布时间】:2019-11-14 01:24:21
【问题描述】:

我在客户端使用以下代码:

import frAppLib from '@feathersjs/feathers'
import frRestLib from '@feathersjs/rest-client'
import auth from '@feathersjs/authentication-client'
import { CookieStorage } from 'cookie-storage'
const cookieStorage = new CookieStorage()

const authOptions = {
  header: 'Authorization', // the default authorization header for REST
  prefix: '', // if set will add a prefix to the header value. for example if prefix was 'JWT' then the header would be 'Authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOi...'
  path: '/authentication', // the server-side authentication service path
  jwtStrategy: 'jwt', // the name of the JWT authentication strategy 
  entity: 'user', // the entity you are authenticating (ie. a users)
  service: 'users', // the service to look up the entity
  cookie: 'feathers-jwt', // the name of the cookie to parse the JWT from when cookies are enabled server side
  storageKey: 'feathers-jwt', // the key to store the accessToken in localstorage or AsyncStorage on React Native
  storage: cookieStorage // Passing a WebStorage-compatible object to enable automatic storage on the client.
}

const feathers = frAppLib()

const apiUrl = process.env.NODE_ENV == 'production'
      ? 'http://localhost:3030' //TODO
      : 'http://localhost:3030'

const frRest = frRestLib(apiUrl)

feathers.configure(frRest.fetch(window.fetch))
feathers.configure(auth(authOptions))


export default feathers

我的注销代码是:

import feathers from '@/feathers.js'
async logoutClick() {
  await feathers.logout()
  this.$router.replace('/login')
}

我的问题如下:

  • 我在我的应用中登录
  • 在浏览器的另一个标签页中打开我的应用
  • 使用我的应用返回第一个选项卡并单击注销

在第一个选项卡注销之后就可以了,但浏览器不会将 delete 发送到 authorisation 服务到服务器。我在浏览器网络活动

中看不到它

所以,我在浏览器第二个标签页中的应用仍然处于登录状态。

如何注销浏览器的所有标签,我的应用在哪里打开?

【问题讨论】:

    标签: feathersjs feathers-authentication


    【解决方案1】:

    如果您使用 JWT 身份验证方法,则默认情况下,服务器不会保存经过身份验证的用户列表。每个请求中的服务器都会反序列化令牌并加载用户对象。

    如果你想实现注销机制,那么你必须创建一个黑名单,保存已注销的用户。 Here 是对主题的一个很好的详细解释。

    我认为 Feathers.js 没有实现黑名单机制。其实在官方documentation中说app.service('authentication')服务的remove方法是用来实现自定义黑名单的。

    在这种情况下,您应该持有一个单独的用户黑名单,并在删除方法之后,插入该列表。当用户登录.create() 时,您应该尝试将用户从该黑名单中删除。最后一件事是防止黑名单中的用户可以访问任何服务,也许除了登录操作。

    所有这些过程都会导致当用户在浏览器选项卡中注销时,该用户将被列入黑名单。然后,当另一个选项卡尝试使用他自己的令牌访问另一个服务时,该用户将无法访问任何服务,因为他已经在黑名单上。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-17
      • 1970-01-01
      • 1970-01-01
      • 2015-05-06
      • 1970-01-01
      • 1970-01-01
      • 2014-01-09
      相关资源
      最近更新 更多