2017-06-05 37 views
0

如果您查看官方羽毛認證插件的默認選項,它說應該有一個用戶對象在hook.params.user中可用(在實體選項下)成功羽毛js認證後,hook.params.user不存在

https://github.com/feathersjs/feathers-authentication

{ 
    path: '/authentication', // the authentication service path 
    header: 'Authorization', // the header to use when using JWT auth 
    **entity: 'user', // the entity that will be added to the request, socket, and hook.params. (ie. req.user, socket.user, hook.params.user)** 
    service: 'users', // the service to look up the entity 
    passReqToCallback: true, // whether the request object should be passed to the strategies `verify` function 
    session: false, // whether to use sessions 
    cookie: { 
    enabled: false, // whether the cookie should be enabled 
    name: 'feathers-jwt', // the cookie name 
    httpOnly: false, // whether the cookie should not be available to client side JavaScript 
    secure: true // whether cookies should only be available over HTTPS 
    }, 
    jwt: { 
    header: { typ: 'access' }, // by default is an access token but can be any type 
    audience: 'https://yourdomain.com', // The resource server where the token is processed 
    subject: 'anonymous', // Typically the entity id associated with the JWT 
    issuer: 'feathers', // The issuing server, application or resource 
    algorithm: 'HS256', // the algorithm to use 
    expiresIn: '1d' // the access token expiry 
    } 
} 

我有一個成功的驗證,我有存儲在一個window.localStorage JWT令牌。我只是不知道如何添加以獲得hook.params.user對象出現。我需要在服務器端設置一些東西嗎?我目前的身份驗證流程只是文檔設置的示例。

我目前的懷疑是這是遺留信息,因爲新文檔沒有提到hook.params.user對象可用,我認爲它只是使用鉤子來插入用戶標識。

https://docs.feathersjs.com/api/authentication/client.html

如果是這樣的話,有沒有辦法只是爲了讓登錄的用戶當前的用戶ID不使用鉤子將其添加嗎?

感謝

回答

0

它仍在增加,但你必須要麼驗證套接字連接或從存儲令牌的HTTP請求。通常通過在之前在客戶端上調用app.authenticate()(無參數)來完成任何其他服務調用。要看到它的行動,看看Vanilla JS chat frontend

+0

啊完美。我沒有意識到每次打開應用程序時都必須調用app.authenticate。我看到用戶對象現在被添加。 – Irlanco