Azard / egg-oauth2-server

:star2: OAuth2 server plugin for egg.js based on node-oauth2-server
MIT License
179 stars 45 forks source link

鉴权之后,如何在 controlle r里面获取用户 ID #45

Closed morelearn1990 closed 5 years ago

morelearn1990 commented 5 years ago

大神您好,鉴权之后,如何在 controlle r 里面获取用户 ID 呀?

morelearn1990 commented 5 years ago

想到该怎么做了,直接获取 headers 里面的token值,直接到数据库里面去查一把。但是每个请求都这样做一遍就很恼火,需要找个地方封装起来方便调用

Azard commented 5 years ago

可以在 oauth.js 里写到 ctx 里

morelearn1990 commented 5 years ago

嗯嗯,我后来写到utils的扩展里了,需要的时候直接调用