Closed sanori closed 7 years ago
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."
This patch upgrades this example to use phases feature of loopback.io https://docs.strongloop.com/display/public/LB/Upgrading+applications+to+use+phases I think this resolves issue #56 , #39 I have consulted the answer in https://github.com/strongloop/loopback-example-middleware/issues/4 . Thanks @hacksparrow.
I tried to remove most of app.middleware
calls in server.js
. But, I cannot change
app.middleware('auth', loopback.token({
model: app.models.accessToken
}));
to middleware.json
entry.
Does anyone solve this problem?
@loay please review.
@raymondfeng @superkhau PTAL too
@sanori thank you for the pull request.
I tried to remove most of app.middleware calls in server.js. But, I cannot change
app.middleware('auth', loopback.token({ model: app.models.accessToken }));
to middleware.json entry.
I believe you can reference the model by name in middleware.json, e.g.
{
"auth": {
"loopback#token": {
"params": { "model": "accessToken" }
}
}
}
@slnode ok to test
@bajtos Thank you for your suggestion. But, in my case, it makes the following error
AssertionError: loopback.token() middleware requires a AccessToken model
at C:\Users\jwjung\Documents\Workspace\loopback-example-passport\node_modules\loopback\server\middleware\token.js:96:5
at Layer.handle [as handle_request] (C:\Users\jwjung\Documents\Workspace\loopback-example-passport\node_modules\loopback\node_mo
dules\express\lib\router\layer.js:95:5)
at trim_prefix (C:\Users\jwjung\Documents\Workspace\loopback-example-passport\node_modules\loopback\node_modules\express\lib\rou
ter\index.js:312:13)
at C:\Users\jwjung\Documents\Workspace\loopback-example-passport\node_modules\loopback\node_modules\express\lib\router\index.js:
280:7
at Function.process_params (C:\Users\jwjung\Documents\Workspace\loopback-example-passport\node_modules\loopback\node_modules\exp
ress\lib\router\index.js:330:12)
at next (C:\Users\jwjung\Documents\Workspace\loopback-example-passport\node_modules\loopback\node_modules\express\lib\router\ind
ex.js:271:10)
at SessionStrategy.strategy.pass (C:\Users\jwjung\Documents\Workspace\loopback-example-passport\node_modules\passport\lib\middle
ware\authenticate.js:318:9)
at SessionStrategy.authenticate (C:\Users\jwjung\Documents\Workspace\loopback-example-passport\node_modules\passport\lib\strateg
ies\session.js:67:10)
at attempt (C:\Users\jwjung\Documents\Workspace\loopback-example-passport\node_modules\passport\lib\middleware\authenticate.js:3
41:16)
at authenticate (C:\Users\jwjung\Documents\Workspace\loopback-example-passport\node_modules\passport\lib\middleware\authenticate
.js:342:7)
I guess, when loading middleware.json
, loopback could not access app.models.accessToken
LGTM except for the access token error
+1
getting as well the error
AssertionError: loopback.token() middleware requires a AccessToken model
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."
Hey guys, I'm having the same problem.
not work
"auth": { "loopback#token": { "params": { "model": "accessToken", "currentUserLiteral": true } } },
work !! app.middleware('auth', app.loopback.token({ model: app.models.accessToken, currentUserLiteral: 'me' }));
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."
I guess that there is no way to set auth token as user defined model in middleware.json, currently. That is, this PR is the best possible way to move middleware functions to middleware.json, I guess. Is it right?
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS
file at the top-level of this repository.
static page handler, error page rendering, and error handler can be configured in
middleware.json
as follows:Currently, it seems that app.middleware() calls in server.js and configuration of middleware.json is mixed.