Comments (10)
Sounds good to me. What do you think, should we still keep it in ctx.request
with a deprecation warning for now?
from koa-passport.
Yeah I think that makes sense. I can put together a PR for this if you want
from koa-passport.
A PR is of course highly welcome, but I am also totally fine with implementing it myself.
from koa-passport.
I'd love to contribute. I'll take a stab at it and see what you think.
from koa-passport.
Before I publish a new version I just like to get some feedback on the methods .login()
, .logout()
, .isAuthenticated()
and .isUnauthenticated()
. They are currently added to both ctx
and ctx.req
. I would also like to clean this up a little bit. What is your opinion for the best location where to put them, ctx
or also ctx.state
?
from koa-passport.
I tend to think of ctx.state
as a simple data store, where logic does not belong, so my preference would be for ctx
.
However, .isAuthenticated()
and .isUnauthenticated()
pertain more to a specific request (depending whether sessions are used), so I could see an argument for adding those two to ctx.req
.
It's hard to say what's best, but if I had to choose one place for all methods, I think ctx
makes the most sense.
from koa-passport.
Thanks for your feedback! I agree on your points. I think .isAuthenticated()
and .isUnauthenticated()
fit into both ctx
and ctx.request
(request
should probably preferred over req
). But since having it both does not make too much sense, I will probably go with ctx
.
from koa-passport.
Before you publish, I just discovered a problem with my implementation that could create a race condition.
Basically, next()
can be called before ctx.state.user
is assigned because resolve
callback is invoked first.
I'll fix in a new PR
from koa-passport.
It appears that the verify
callback in strategies use the req setter. E.g. https://github.com/jaredhanson/passport-http/blob/master/lib/passport-http/strategies/basic.js#L95
I checked the stack trace:
at IncomingMessage.Object.defineProperty.set [as user] (\node_modules\koa-passport\lib\framework\koa.js:37:19)
at Object.properties.(anonymous function).set (\node_modules\koa-passport\lib\framework\request.js:113:16)
at Object.req.login.req.logIn (\node_modules\passport\lib\http\request.js:44:18)
at Object.<anonymous> (\node_modules\koa-passport\lib\framework\request.js:104:27)
at BasicStrategy.strategy.success (\node_modules\passport\lib\middleware\authenticate.js:235:13)
at verified (\node_modules\passport-http\lib\passport-http\strategies\basic.js:91:10)
So this deprecation notice is unavoidable it seems.
Should I open a new issue?
from koa-passport.
Thanks for reporting, I've created an issue for this: #66
from koa-passport.
Related Issues (20)
- koa-passport doesn't work with local-strategy? HOT 1
- Delegate Koa's ctx.protocol in request HOT 1
- external session storage does not work HOT 2
- The callback in ctx.login() is not being executed, "Error: Failed to serialize user into session" HOT 9
- Strange behavior for passport.authenticate() function HOT 8
- passport.authenticate("jwt", {session: false}) will not executed. Does koa-passport support JWT strategies? HOT 1
- passport serialize user: next is not a function HOT 2
- mocking request loses original koa app instance, breaking resolving of req.subdomains, because req.app.subdomainOffset is undefined HOT 4
- Documentation | authenticate() HOT 2
- Use koa-passport without koa-session HOT 1
- Not work well with @koa/router in Typescript HOT 2
- koa-passport@next is broken! HOT 1
- Passing multiple strategies to passport.authenticate() HOT 1
- export `AuthenticateOptions` HOT 1
- Should `ctx.state.user` contains `password`? HOT 1
- Update passport to latest version HOT 2
- req.session.regenerate is not a function HOT 17
- Mix of express/koa with passport in both breaks HOT 3
- Passport authentification - LocalStrategy async/await issue
- userProperty option doesn't work
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from koa-passport.