Skip to content
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

user-order.controller.ts doesn't auth with @authenticate('jwt') #43

Closed
lygstate opened this issue Feb 8, 2019 · 9 comments
Closed

user-order.controller.ts doesn't auth with @authenticate('jwt') #43

lygstate opened this issue Feb 8, 2019 · 9 comments
Labels
Authentication good first issue Good for newcomers help wanted Extra attention is needed

Comments

@lygstate
Copy link

lygstate commented Feb 8, 2019

user-order.controller.ts doesn't auth with @authenticate('jwt'),
besides, doesn't check the userId

    if (userId !== currentUser.id) {
      throw new HttpErrors.BadRequest(
        `User id does not match: ${userId} !== ${currentUser.id}`,
      );
    }
@jannyHou
Copy link
Contributor

@lygstate

if (userId !== currentUser.id) {
      throw new HttpErrors.BadRequest(
        `User id does not match: ${userId} !== ${currentUser.id}`,
      );
    }

This is an authorization scenario which we are planning to implement after building the fundamental extensible authentication system.

@lygstate
Copy link
Author

@jannyHou Sounds great, what's I can help.

@jannyHou
Copy link
Contributor

@lygstate Thank you for being interested to help!

The story that tracks this change is loopbackio/loopback-next#1998, we are planning to add some abstractions in @loopback/authentication module then refactor this example repo to leverage them.
I will let you know if we decide story#1998 can start with the refactor in parallel or before it. And we can help you work on the PR that enable the auth for orders.

@bajtos
Copy link
Member

bajtos commented Feb 28, 2019

Before the work on the actual authorization is started, perhaps @lygstate can contribute the authentication changes we left out of February milestone? Cross-posting from loopbackio/loopback-next#1998:

Rework UserOrderController to obtain the customer id from the request (the access token provided by the client) instead of a URL-path parameter.

For example, we can remove /users/{userId} prefix from all endpoints to end up with the following API:

  • POST /orders creates a new order
  • GET /orders returns all orders of the current user
  • PATCH /orders?where= to update some of the orders of the current user. I think this endpoint does not make sense in a Shopping app and should be eventually removed.
  • DELETE /orders?where= to delete some of the orders of the current user. I think this endpoint should be eventually removed, because orders are never deleted, they can be only closed (e.g. as cancelled).

Existing REST API exposed by UserController should remain unauthenticated (allowing anonymous access).

@dhmlau dhmlau added help wanted Extra attention is needed good first issue Good for newcomers labels Mar 1, 2019
@jannyHou
Copy link
Contributor

jannyHou commented Mar 4, 2019

@bajtos Yeah sounds good 👍
Hi @lygstate would you be interested to submit a PR according to the description cross posted in #43 (comment)?

@austin047
Copy link

Hello, I am new to loopback4 and github in general.
I have basic knowledge on nodejs and express, i will like to work on this issue. I will be glad if i can get some hints on where to start.

@bajtos
Copy link
Member

bajtos commented Mar 22, 2019

Hi @austin047, it's great to hear you are interested in helping out!

We have a detailed guide showing how to fork loopback-next repository on GitHub, create a feature branch, etc. see https://loopback.io/doc/en/lb4/submitting_a_pr.html

As for this particular task, you will need to make changes in the following files:

Good luck 🍀

@austin047
Copy link

Thanks.

austin047 added a commit to austin047/loopback4-example-shopping that referenced this issue Mar 30, 2019
…e a new order

Updated the create order method that handles post request to create a user order to authenticate
against the current user before an order can be created, the client will have to pass the
authentication token in the request header which will be authenticated before the order is created

BREAKING CHANGE: For an order to be created the client must pass the authentication token in the
request header, otherwise a 401 Unauthorized error will be generated

feat loopbackio#43
austin047 added a commit to austin047/loopback4-example-shopping that referenced this issue Mar 30, 2019
…e a new order

Updated the create order method that handles post request to create a user order to authenticate
against the current user before an order can be created, the client will have to pass the
authentication token in the request header which will be authenticated before the order is created

BREAKING CHANGE: For an order to be created the client must pass the authentication token in the
request header, otherwise a 401 Unauthorized error will be generated

feat loopbackio#43
austin047 added a commit to austin047/loopback4-example-shopping that referenced this issue Mar 30, 2019
…e a new order

Updated the create order method that handles post request to create a user order to authenticate
against the current user before an order can be created, the client will have to pass the
authentication token in the request header which will be authenticated before the order is created

BREAKING CHANGE: For an order to be created the client must pass the authentication token in the
request header, otherwise a 401 Unauthorized error will be generated

feat loopbackio#43

Signed-off-by: austin047 <[email protected]>
austin047 added a commit to austin047/loopback4-example-shopping that referenced this issue Apr 9, 2019
…e a new order

Updated the create order method that handles post request to create a user order to authenticate
against the current user before an order can be created, the client will have to pass the
authentication token in the request header which will be authenticated before the order is created

BREAKING CHANGE: For an order to be created the client must pass the authentication token in the
request header, otherwise a 401 Unauthorized error will be generated

feat loopbackio#43

Signed-off-by: austin047 <[email protected]>
jannyHou pushed a commit to austin047/loopback4-example-shopping that referenced this issue Apr 29, 2019
…e a new order

Updated the create order method that handles post request to create a user order to authenticate
against the current user before an order can be created, the client will have to pass the
authentication token in the request header which will be authenticated before the order is created

BREAKING CHANGE: For an order to be created the client must pass the authentication token in the
request header, otherwise a 401 Unauthorized error will be generated

feat loopbackio#43

Signed-off-by: austin047 <[email protected]>
austin047 pushed a commit to austin047/loopback4-example-shopping that referenced this issue Jun 19, 2019
Client can create an order without passing the userId in the body of the
request, the serve collects the userId from the url and compares against
the authenticated user(Current User) and the creates the order for that
user.

✅ Closes: loopbackio#43

refactor: 💡 remove debug console logs

Remove console logs created for debug purposes
austin047 pushed a commit to austin047/loopback4-example-shopping that referenced this issue Jun 19, 2019
Client can create an order without passing the userId in the body of the
request, the serve collects the userId from the url and compares against
the authenticated user(Current User) and the creates the order for that
user.

✅ Closes: loopbackio#43

refactor: 💡 remove debug console logs

Remove console logs created for debug purposes

Signed-off-by: Fuh Austin <austin047>
austin047 pushed a commit to austin047/loopback4-example-shopping that referenced this issue Jun 19, 2019
Client can create an order without passing the userId in the body of the
request, the serve collects the userId from the url and compares against
the authenticated user(Current User) and the creates the order for that
user.

✅ Closes: loopbackio#43

refactor: 💡 remove debug console logs

Remove console logs created for debug purposes

Signed-off-by: Fuh Austin <[email protected]>
austin047 pushed a commit to austin047/loopback4-example-shopping that referenced this issue Jun 19, 2019
Client can create an order without passing the userId in the body of the
request, the serve collects the userId from the url and compares against
the authenticated user(Current User) and the creates the order for that
user.

✅ Closes: loopbackio#43

refactor: 💡 remove debug console logs

Remove console logs created for debug purposes

Signed-off-by: Fuh Austin <[email protected]>
austin047 pushed a commit to austin047/loopback4-example-shopping that referenced this issue Jun 19, 2019
Client can create an order without passing the userId in the body of the
request, the serve collects the userId from the url and compares against
the authenticated user(Current User) and the creates the order for that
user.

✅ Closes: loopbackio#43

refactor: 💡 remove debug console logs

Remove console logs created for debug purposes

Signed-off-by: austin047 <[email protected]>
austin047 pushed a commit to austin047/loopback4-example-shopping that referenced this issue Jun 19, 2019
Client can create an order without passing the userId in the body of the
request, the serve collects the userId from the url and compares against
the authenticated user(Current User) and the creates the order for that
user.

✅ Closes: loopbackio#43

refactor: 💡 remove debug console logs

Remove console logs created for debug purposes

Signed-off-by: austin047 <[email protected]>
austin047 added a commit to austin047/loopback4-example-shopping that referenced this issue Jun 19, 2019
Client can create an order without passing the userId in the body of the
request, the serve collects the userId from the url and compares against
the authenticated user(Current User) and the creates the order for that
user.

✅ Closes: loopbackio#43

refactor: 💡 remove debug console logs

Remove console logs created for debug purposes

Signed-off-by: Fuh Austin <[email protected]>
@dhmlau
Copy link
Member

dhmlau commented Feb 24, 2020

Closing as fixed.

@dhmlau dhmlau closed this as completed Feb 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Authentication good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants