-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
loopback.getCurrentContext() is null when setting the accessToken from a cookie. #1747
Comments
I've found a hacky solution that fit with my needs for now but doesn't work with ACL. : "remoting": {
"context": {
"enableHttpContext": true
}
} 2 - using the ctx.http.req.accessToken Coder.current = function(cb){
var context = loopback.getCurrentContext().active;
return Coder.findById(context.http.req.accessToken.coderId)
}; 3 - ACL restrictions does not work (401 even when i'm authenticated) {
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "current",
"accessType": "EXECUTE"
} My question: It is possible to combine Passport + Built-in ACL ? If so, can someone tells me how, cause it's driving me crazy. Thanks! |
👍 |
Found the solution to get the accessToken from the currentContext, from the cookie. "session": {},
"session:after":{
"loopback#context": {}
},
"auth": {},
"parse": {},
"routes": {
"loopback#rest": {
"paths": [
"${restApiRoot}"
]
}
} And set the custom AccessToken model (AuthToken for me) after the boot app.use(loopback.token({model: app.models.AuthToken})); i'm still having an issue with ACL that does not work. But i'll open another issue. |
Last message, fixed the problem with ACL, the relation between my custom User model (Coder) had a foreign key with my custom AccessToken (AuthToken) named |
Possibly related : #1676 |
Going to keep discussion on #1676 and close this issue, thanks. |
I had to dig into the sources to understand why the accessToken was available from req.signedCookies but not set on the current context, even after adding :
And i came to this (middleware/token.js)
The token is properly fetched but the context is always null.
I tried to understand the context creation flow and it seems that you initialize the context during the routes:loopback#rest which is (i think) too late for those who we need to bind something to the context before the route execution.
I'm pretty new to loopback so i might have missed something.
EDIT: Still looking for a solution to make the accessToken available from the context. Thanks.
The text was updated successfully, but these errors were encountered: