Closed TommyBez-old closed 5 years ago
@TommyBez How is your controller function decorated with @authenticate()
? Looks like you didn't specify a strategy name as the first parameter, the correct syntax is sth like @authenticate('jwt')
.
@jannyHou Actually it is the controller provided in the example from the documentation. Anyway I get the error for any route/controller. Debugging the application, I've found out it's not calling MyAuthStrategyProvider at all. I've tried to delete AuthenticationMetadata injection and always return BasicStrategy as value and it works. It seems the issue is happening at dependency resolver level.
I found a similar issue using the latest version of @loopback/context 1.7.0 , when you do an npm link from a component folder to your application project I receive a similar issue. Error: Cannot resolve injected arguments for LogActionProvider.[0]: The arguments[0] is not decorated for dependency injection, but a value is not supplied
@TommyBez try to fix the npm versions , remove the ^ for all the loopback packages, after that it will work.
Can you try to run npm ls reflect-metadata
to see if there are multiple versions?
@TommyBez Can you share a github repo to reproduce the problem?
@raymondfeng this is the result running npm ls reflect-metadata
:
+-- @loopback/authentication@1.0.15
| `-- @loopback/metadata@1.0.8
| `-- reflect-metadata@0.1.12
+-- @loopback/context@1.5.0
| `-- @loopback/metadata@1.0.5
| `-- reflect-metadata@0.1.12 deduped
`-- @loopback/tslint-config@2.0.0
`-- tslint-consistent-codestyle@1.15.0
`-- @fimbul/bifrost@0.17.0
`-- @fimbul/ymir@0.17.0
`-- reflect-metadata@0.1.12 deduped
I don't have a github repo to share, anyway you can easily reproduce the scenario with a simple Rest application with the authentication example representation. Here below my current package.json dependencies:
"dependencies": {
"@loopback/authentication": "^1.0.15",
"@loopback/boot": "^1.0.11",
"@loopback/context": "^1.5.0",
"@loopback/core": "^1.1.5",
"@loopback/openapi-v3": "^1.2.0",
"@loopback/repository": "^1.1.4",
"@loopback/rest": "^1.5.4",
"@loopback/rest-explorer": "^1.1.7",
"@loopback/service-proxy": "^1.0.7",
"@types/bcrypt": "^3.0.0",
"@types/jsonwebtoken": "^8.3.2",
"bcrypt": "^3.0.4",
"fs": "0.0.1-security",
"loopback-connector-postgresql": "^3.6.0",
"passport": "^0.4.0",
"passport-http": "^0.3.0"
},
"devDependencies": {
"@loopback/build": "^1.2.1",
"@loopback/testlab": "^1.0.5",
"@loopback/tslint-config": "^2.0.0",
"@types/node": "^10.11.2",
"@types/passport": "^1.0.0",
"@types/passport-http": "^0.3.7",
"tslint": "^5.12.0",
"typescript": "^3.2.2"
}
@JamilOmar I've tried removing ^ and reinstalling all loopback packages but unfortunately it didn't fix it.
@JamilOmar Could you tell me the exact @loopback/context and @loopback/authentication versions you are using? Thank you.
@TommyBez
"dependencies": {
"@loopback/boot": "1.0.12",
"@loopback/context": "1.6.0",
"@loopback/core": "1.1.6",
"@loopback/openapi-v3": "1.2.1",
"@loopback/repository": "1.1.5",
"@loopback/rest": "1.5.5",
"@loopback/rest-explorer": "1.1.8",
"@loopback/service-proxy": "1.0.8",
"memory": "0.0.3"
},
"devDependencies": {
"@loopback/build": "1.3.0",
"@loopback/testlab": "1.0.6",
"@loopback/tslint-config": "2.0.0",
"@types/node": "^10.11.2",
"tslint": "^5.12.0",
"typescript": "^3.3.1"
},
Test that , I was able to run it on my local.
Hi, I can reproduce the problem now. It turns out you have mixed versions of @loopback/context
. Please run npm ls @loopback/context
and make sure only one consistent version is used. There was a breaking
change introduced in @loopback/context@1.7.0
and we didn't anticipate the mixed versions of this module are used.
You can use lb4 --version
command to see a list of compatible versions of @loopback/*
modules.
BTW, if you install the latest version of @loopback/cli
and run lb4 model
or other commands in your old project, it will prompt you something like:
lb4 model
The project has dependencies with incompatible versions required by the CLI:
- typescript: 3.2.2 (cli ^3.3.1)
- @loopback/boot: 1.0.11 (cli ^1.1.0)
- @loopback/build: 1.2.1 (cli ^1.3.2)
- @loopback/context: 1.5.0 (cli ^1.7.0)
- @loopback/core: 1.1.5 (cli ^1.1.8)
- @loopback/openapi-v3: 1.2.0 (cli ^1.3.0)
- @loopback/repository: 1.1.4 (cli ^1.1.8)
- @loopback/rest: 1.5.4 (cli ^1.8.0)
- @loopback/testlab: 1.0.5 (cli ^1.1.0)
- @loopback/service-proxy: 1.0.7 (cli ^1.0.10)
- @loopback/rest-explorer: 1.1.7 (cli ^1.1.11)
- @loopback/tslint-config: 2.0.0 (cli ^2.0.2)
I have a similar problem which started also from trying to implement the authentication,. The "metadata" is not inserted in the strategy and I have no idea how to fix it. From the previous I understand that probably this is related to different "context" versions.
npm ls @loopback/context
│ ├── @loopback/context@1.8.0
│ ├─┬ @loopback/core@1.2.0
│ │ └── @loopback/context@1.8.0 deduped
│ ├─┬ @loopback/openapi-v3@1.3.1
│ │ ├── @loopback/context@1.8.0 deduped
│ │ └─┬ @loopback/repository-json-schema@1.3.5
│ │ ├── @loopback/context@1.8.0 deduped
│ │ └─┬ @loopback/repository@1.2.0
│ │ └── @loopback/context@1.8.0 deduped
│ └─┬ @loopback/rest@1.9.0
│ └── @loopback/context@1.8.0 deduped
├─┬ @loopback/boot@1.1.0
│ └── @loopback/context@1.7.0 deduped
├── @loopback/context@1.7.0
├─┬ @loopback/core@1.1.8
│ └── @loopback/context@1.7.0 deduped
├─┬ @loopback/openapi-v3@1.3.0
│ ├── @loopback/context@1.7.0 deduped
│ └─┬ @loopback/repository-json-schema@1.3.4
│ └── @loopback/context@1.7.0 deduped
├─┬ @loopback/repository@1.1.8
│ └── @loopback/context@1.7.0 deduped
├─┬ @loopback/rest@1.8.0
│ └── @loopback/context@1.7.0 deduped
├─┬ @loopback/rest-explorer@1.1.11
│ └── @loopback/context@1.7.0 deduped
└─┬ @loopback/service-proxy@1.0.10
└── @loopback/context@1.7.0 deduped
lb4 --version
@loopback/* dependencies:
- @loopback/authentication: ^1.0.15
- @loopback/boot: ^1.1.0
- @loopback/build: ^1.3.2
- @loopback/context: ^1.7.0
- @loopback/core: ^1.1.8
- @loopback/metadata: ^1.0.8
- @loopback/openapi-spec-builder: ^1.1.0
- @loopback/openapi-v3-types: ^1.0.8
- @loopback/openapi-v3: ^1.3.0
- @loopback/repository-json-schema: ^1.3.4
- @loopback/repository: ^1.1.8
- @loopback/rest: ^1.8.0
- @loopback/testlab: ^1.1.0
- @loopback/docs: ^1.10.0
- @loopback/example-hello-world: ^1.1.6
- @loopback/example-log-extension: ^1.1.6
- @loopback/example-rpc-server: ^1.1.5
- @loopback/example-todo: ^1.5.1
- @loopback/example-soap-calculator: ^1.4.1
- @loopback/service-proxy: ^1.0.10
- @loopback/http-caching-proxy: ^1.0.9
- @loopback/http-server: ^1.1.8
- @loopback/example-todo-list: ^1.5.1
- @loopback/dist-util: ^0.4.0
- @loopback/rest-explorer: ^1.1.11
- @loopback/tslint-config: ^2.0.2
- @loopback/example-express-composition: ^1.2.1
Adding answer to my own problem after I found it.
I changed the dependencies to latest. Even that I was using "theoretically" the latest it didn't work. When I changed manually to :
"@loopback/authentication": "^1.0.16",
"@loopback/boot": "^1.1.2",
"@loopback/context": "^1.8.1",
"@loopback/core": "^1.2.1",
"@loopback/openapi-v3": "^1.3.2",
"@loopback/repository": "^1.2.1",
"@loopback/rest": "^1.9.1",
"@loopback/rest-explorer": "^1.1.13",
"@loopback/service-proxy": "^1.1.1",
"loopback-connector-postgresql": "^3.6.0",
"passport": "^0.4.0",
"passport-http": "^0.3.0"```
started to work
@raymondfeng I have a similar issue and packages version doesn't seems to be the cause.
The problem started to arise in our migrate script when we added a request context bound value (that we set in a sequence action) to our repository classes. At first I get
Cannot migrate database schema Error: The key 'authentication.currentUser' is not bound to any value in context application
fine, lets bind it our migrate script (hoping I'll will not have too many of those), and then I get
Cannot migrate database schema Error: Cannot resolve injected arguments for RepositoryBase.[0]: The arguments[0] is not decorated for dependency injection, but a value is not supplied
And now I'm lost.
I'm using a similar way of setting the CURRENT_USER
as in the Authentication package,
For reference, packages versions:
+-- @loopback/boot@1.2.4
| `-- @loopback/context@1.12.1 deduped
+-- @loopback/context@1.12.1
+-- @loopback/core@1.6.1
| `-- @loopback/context@1.12.1 deduped
+-- @loopback/openapi-v3@1.3.8
| +-- @loopback/context@1.12.1 deduped
| `-- @loopback/repository-json-schema@1.4.4
| `-- @loopback/context@1.12.1 deduped
+-- @loopback/repository@1.5.2
| `-- @loopback/context@1.12.1 deduped
+-- @loopback/rest@1.10.5
| `-- @loopback/context@1.12.1 deduped
+-- @loopback/rest-explorer@1.1.19
| `-- @loopback/context@1.12.1 deduped
`-- @loopback/service-proxy@1.1.7
`-- @loopback/context@1.12.1 deduped
Try to run npm update
.
@raymondfeng I've removed the node_modules
folder, cleared npm cache, updated manually @loopback deps version and reinstalled everything with the latest version and I'm still having the exact same issue.
+-- @loopback/boot@1.2.5
| `-- @loopback/context@1.13.0 deduped
+-- @loopback/context@1.13.0
+-- @loopback/core@1.6.2
| `-- @loopback/context@1.13.0 deduped
+-- @loopback/openapi-v3@1.3.9
| +-- @loopback/context@1.13.0 deduped
| `-- @loopback/repository-json-schema@1.4.5
| `-- @loopback/context@1.13.0 deduped
+-- @loopback/repository@1.5.3
| `-- @loopback/context@1.13.0 deduped
+-- @loopback/rest@1.11.0
| `-- @loopback/context@1.13.0 deduped
+-- @loopback/rest-explorer@1.1.20
| `-- @loopback/context@1.13.0 deduped
`-- @loopback/service-proxy@1.1.8
`-- @loopback/context@1.13.0 deduped
Is it a duplicate of https://github.com/strongloop/loopback-next/issues/2541?
@raymondfeng I seem to have the same issue. Using the example code results in the following error
src/application.ts:20:60 - error TS2345: Argument of type 'typeof MyAuthStrategyProvider' is not assignable to parameter of type 'Constructor<Provider<AuthenticationStrategy | undefined>>'. Type 'MyAuthStrategyProvider' is not assignable to type 'Provider<AuthenticationStrategy | undefined>'. Types of property 'value' are incompatible. Type '() => ValueOrPromise<Strategy | undefined>' is not assignable to type '() => ValueOrPromise<AuthenticationStrategy | undefined>'. Type 'ValueOrPromise<Strategy | undefined>' is not assignable to type 'ValueOrPromise<AuthenticationStrategy | undefined>'. Type 'Strategy' is not assignable to type 'ValueOrPromise<AuthenticationStrategy | undefined>'. Type 'Strategy' is not assignable to type 'AuthenticationStrategy'. Types of property 'name' are incompatible. Type 'string | undefined' is not assignable to type 'string'. Type 'undefined' is not assignable to type 'string'.
20 this.bind(AuthenticationBindings.STRATEGY).toProvider( MyAuthStrategyProvider );
Using the versions specified by @danysz it seems to work
just upgrading @loopback/authentication only to 2.0.2 results in the same error.
here are some details on combinations I have tried so far.
My environment: Global lb4 --version
@loopback/cli version: 1.12.1
@loopback/* dependencies:
- @loopback/authentication: ^2.0.2
- @loopback/boot: ^1.2.6
- @loopback/build: ^1.5.3
- @loopback/context: ^1.14.0
- @loopback/core: ^1.6.3
- @loopback/metadata: ^1.1.3
- @loopback/openapi-spec-builder: ^1.1.9
- @loopback/openapi-v3-types: ^1.0.17
- @loopback/openapi-v3: ^1.3.10
- @loopback/repository-json-schema: ^1.4.6
- @loopback/repository: ^1.5.4
- @loopback/rest: ^1.11.1
- @loopback/testlab: ^1.2.8
- @loopback/docs: ^1.17.1
- @loopback/example-hello-world: ^1.1.16
- @loopback/example-log-extension: ^1.1.16
- @loopback/example-rpc-server: ^1.1.15
- @loopback/example-todo: ^1.5.11
- @loopback/example-soap-calculator: ^1.4.11
- @loopback/service-proxy: ^1.1.9
- @loopback/http-caching-proxy: ^1.0.18
- @loopback/http-server: ^1.2.2
- @loopback/example-todo-list: ^1.5.11
- @loopback/dist-util: ^0.4.0
- @loopback/rest-explorer: ^1.1.21
- @loopback/tslint-config: ^2.0.4
- @loopback/example-express-composition: ^1.2.11
- @loopback/example-greeter-extension: ^1.2.3
- @loopback/booter-lb3app: ^1.1.2
Output of -----npm ls @loopback/context
agctm@1.0.0 /home/vagrant/test/agctm
├─┬ @loopback/authentication@1.2.1 -------- upgrading this to 2.0.2 results in above error
│ └── @loopback/context@1.14.0 deduped
├─┬ @loopback/boot@1.2.6
│ └── @loopback/context@1.14.0 deduped
├── @loopback/context@1.14.0
├─┬ @loopback/core@1.6.3
│ └── @loopback/context@1.14.0 deduped
├─┬ @loopback/openapi-v3@1.3.10
│ ├── @loopback/context@1.14.0 deduped
│ └─┬ @loopback/repository-json-schema@1.4.6
│ └── @loopback/context@1.14.0 deduped
├─┬ @loopback/repository@1.5.4
│ └── @loopback/context@1.14.0 deduped
├─┬ @loopback/rest@1.11.1
│ └── @loopback/context@1.14.0 deduped
├─┬ @loopback/rest-explorer@1.1.21
│ └── @loopback/context@1.14.0 deduped
└─┬ @loopback/service-proxy@1.1.9
└── @loopback/context@1.14.0 deduped
curl -X GET "http://localhost:3000/whoami" -H "accept: */*"
Error: Unauthorized.
{
"error": {
"statusCode": 401,
"name": "UnauthorizedError",
"message": "Basic realm=\"Users\""
}
}
Response headers
access-control-allow-credentials: true access-control-allow-origin: * connection: keep-alive content-length: 89 content-type: application/json; charset=utf-8 date: Mon, 13 May 2019 14:54:47 GMT x-content-type-options: nosniff x-powered-by: Express
Also tried to update all the packages to the latest versions ---- npm ls @loopback/context
agctm@1.0.0 /home/vagrant/test/agctm
├─┬ @loopback/authentication@2.0.2
│ └── @loopback/context@1.14.0 deduped
├─┬ @loopback/boot@1.2.6
│ └── @loopback/context@1.14.0 deduped
├── @loopback/context@1.14.0
├─┬ @loopback/core@1.6.3
│ └── @loopback/context@1.14.0 deduped
├─┬ @loopback/openapi-v3@1.3.10
│ ├── @loopback/context@1.14.0 deduped
│ └─┬ @loopback/repository-json-schema@1.4.6
│ └── @loopback/context@1.14.0 deduped
├─┬ @loopback/repository@1.5.4
│ └── @loopback/context@1.14.0 deduped
├─┬ @loopback/rest@1.11.1
│ └── @loopback/context@1.14.0 deduped
├─┬ @loopback/rest-explorer@1.1.21
│ └── @loopback/context@1.14.0 deduped
└─┬ @loopback/service-proxy@1.1.9
└── @loopback/context@1.14.0 deduped
Please let me know if you need more info.
Looking forward to some pointers in getting this resolved.
Thanks
try to change the version of your loopback-authentificate. like tthat "@loopback/authentication": "^1.0.16",
@raymondfeng - Thx for the pointer. @bajtos I do have a couple of question for you. Is there an example available for Angular - JWT user authentication that one could look at? Any plans to support loopback-sdk-angular or any alternatives available one could investigate?
@DimitriEmman Thx, I will give 1.0.16 a try.
Is there an example available for Angular - JWT user authentication that one could look at?
If LB4 authentication is implemented I could put together an example for that with ng. It is essentially using something like auth0/angular-jwt to do leg work. I'll take a look next week if you like, dependant on the state of LB4 auth implementation.
Any plans to support loopback-sdk-angular or any alternatives available one could investigate?
Something like openapitools/openapi-generator-cli? I've been experimenting with it, it's fairly decent. There will be other tools that support openapi v3.
Is there an example available for Angular - JWT user authentication that one could look at?
If LB4 authentication is implemented I could put together an example for that with ng. It is essentially using something like auth0/angular-jwt to do leg work. I'll take a look next week if you like, dependant on the state of LB4 auth implementation.
@dougal83 Yes, a working example with loopback-authentication v1.x would be greatly appreciated.
Any plans to support loopback-sdk-angular or any alternatives available one could investigate?
Something like openapitools/openapi-generator-cli? I've been experimenting with it, it's fairly decent. There will be other tools that support openapi v3. @dougal83 Thanks for the pointer, I will look into it.
@argupta23 Hey, I found time to put rough working example together. I think the lb4 auth is still in development, so will need to update but it works as intended. I've implemented lb4-ng combo, openapi-generator and JWT auth. Tried to put reasonable effort into readme. Let me know if there are issues that need resolving.
@argupta23 Hey, I found time to put rough working example together. I think the lb4 auth is still in development, so will need to update but it works as intended. I've implemented lb4-ng combo, openapi-generator and JWT auth. Tried to put reasonable effort into readme. Let me know if there are issues that need resolving.
@dougal83. This is great, I tested it and it works. I used mongodb instead. One quick note, please add "isemail" package to the server side package.json file. Would it be possible for me to contact you directly? this way I am not hijacking this thread. Thanks
@argupta23 I've added email to my git profile. Anything regarding that repo though, discus on issues there incase it helps others. Will add dependency cheers.
@argupta23 I've added email to my git profile. Anything regarding that repo though, discus on issues there incase it helps others. Will add dependency cheers.
@dougal83, I have sent you an email. thx.
@raymondfeng related to my comment above https://github.com/strongloop/loopback-next/issues/2582#issuecomment-491085786, I found the cause of my problem.
This is because I have a custom RepositoryBase and it was named base.repository.ts
which causes this file to be automatically bound and instanciated by LB, renaming the file solved the issue. I'm actually surprised to see all repo being instanciated even if they are not injected in any other class.
update everything to latest version and auth is broken again ... this is driving crazy.
"@loopback/authentication": "^2.1.0",
"@loopback/boot": "^1.3.0",
"@loopback/cli": "^1.15.1",
"@loopback/context": "^1.18.0",
"@loopback/core": "^1.8.0",
"@loopback/openapi-v3": "^1.6.0",
"@loopback/repository": "^1.6.0",
"@loopback/rest": "^1.14.0",
"@loopback/rest-explorer": "^1.2.0",
"@loopback/service-proxy": "^1.2.0",
"firebase-admin": "^8.0.0",
"loopback-connector-postgresql": "^3.6.1",
"passport": "^0.4.0",
"passport-firebase-auth": "0.0.0-beta.1",
"passport-http": "^0.3.0",
"uuid": "^3.3.2"
any idea ?
Please see the discussion in https://github.com/strongloop/loopback-next/issues/2886 .
At the moment the passport support for @loopback/authentication 2.x is not available, but is being worked on.
loopback4-example-shopping was updated to use @loopback/authentication 2.x (but doesn't use passport).
In my case, I had a problem like this one using an abstract class for SoftCrudRepository and SoftDeleteEntity.
rm -rf dist && npm run clean && npm run build
solved
Description / Steps to reproduce / Feature proposal
I have followed and set up via @loopback/authentication as described here: https://github.com/strongloop/loopback-next/blob/master/packages/authentication/README.md
Error while accessing any route
application.ts
sequence.ts
auth-strategy.provider.ts
Current Behavior
Expected Behavior