-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
LB4 - Authorization Implementation - Cannot find name AuthResponse - Authorization sample #2896
Comments
@venkatamandala feat: resolve authentication strategy registered via extension point landed in early May and it was a breaking change. Draft:Changes to passport strategy adapter will be updating how passport strategies are handled given the new authentication strategy interface. We are exploring a few options right now. Once things have been decided, the documentation you mention will be updated. refactor shopping cart example to utilize latest @loopback/authentication module is also in the works at the moment. So please stay tuned... :) |
See #1205 |
@venkatamandala AuthResponse is actually the authenticated User Model. Its implementation is not described in the documentation as it can vary application to application. In general, AuthResponse is the returned user model after authentication. You can use the User Model as well, in place of it. |
@samarpanB AuthenticateFn from @loopback/authentication return UserProfile or undefined. Since I use custom User model, it will cause an error because it's not assignable. Do you have any suggestion? |
@bgleolalahi Whatever you return from @loopback/authentication, you should use that as authUser type. You only need to make sure that it contains permissions. |
@bgleolalahi, does @samarpanB answer your question? Is this issue good to close? Thanks. |
Okay, thank you for helping. @samarpanB @dhmlau Yes, we can close the issue now. Thanks. |
hello i have the same problem.i am using loopback/authentification.help please |
@DimitriEmman , please have a look at my replies above for solution. If you still face issues, I would need more information on what error you are getting before I can help with that. Please note this issue was for Authorization implementation not for authentication. If you are facing issues with authentication, please look for existing issues about authentication (if any) related to your problem and any solutions provided there. Or else, you can also raise a new issue providing more details about it. Hope this helps. Thanks. |
Hi @samarpanB thanks for replying. import { UserPermissionsFn } from './authorization/types'; import { const SequenceActions = RestBindings.SequenceActions; export class MySequence implements SequenceHandler { async handle(context: RequestContext) {
}
|
i am not using loopback4-authentication but loopback-authentication |
You can compare/copy code from a working example: LB4 Shopping example /w auth |
@dougal83 did you integrate the authorization in this example(shopping example)? |
@DimitriEmman No, it's an official example /w auth implemented by @emonddr & @jannyHou. I think they have/or are sorting out documentation atm. I've managed to copy the example code into my project /wo error so it's viable. Study the example if the docs are not ready yet. |
Some docs were finally merged into the repo last night, although they still need to be released to loopback.io. Please take a look at : @loopback/authentication/README.MD still needs to be revised. This is in progress at the moment. Hope this helps. |
@DimitriEmman , @dougal83 ^^ :) |
@DimitriEmman , @dougal83 ^^ |
@emonddr thanks.what about role and permissions in loopback 4.I follow these steps https://loopback.io/doc/en/lb4/Loopback-component-authorization.html but it doesn't work |
@DimitriEmman I think I know the issue you are facing. Can you please replace AuthResponse with UserProfile everywhere? That is what is returned by authenticate method. Also in order to make authorisation work, you need to add permissions to the UserProfile model. Please check it out. |
hello @samarpanB thank you for replying.i try to replace authresponse by userprofile and i have again problems. |
If you can share your code on github somewhere, I can then debug and help you out. It’s difficult to figure out otherwise . |
Good morning , |
Hello @DimitriEmman , I can see lots of issues in your codebase unfortunately.
I think what you need to do is follow the authentication documentation shared by @emonddr carefully first. Try to complete the authentication integration successfully first. Sorry I cannot share fully fixed code in your repo. Running little busy to do that. You can refer to our starter project for such guidance. But remember that project is not using @loopback/authentication. It's using loopback4-authentication. |
@samarpanB thanks for the help.i will fix the issues |
Closing due to inactivity. |
Description / Steps to reproduce / Feature proposal
I followed the Authorization tutorial at https://loopback.io/doc/en/lb4/Loopback-component-authorization.html and i have compilation error in "sequence.ts" at AuthResponse Statement (see below)
const authUser: AuthResponse = await this.authenticateRequest(request);
Cannot find name 'AuthResponse'
NOTE: I followed and completed the Authentication piece and getting token successfully in Authentication flow. Please help where i am doing wrong. I followed the exact article provided.
Please check below code for Sequence.ts
import { inject } from '@loopback/context';
import {
FindRoute,
InvokeMethod,
ParseParams,
Reject,
RequestContext,
RestBindings,
Send,
SequenceHandler,
HttpErrors,
} from '@loopback/rest';
import { AuthenticationBindings, AuthenticateFn } from '@loopback/authentication';
import {
AuthorizatonBindings,
AuthorizeFn,
AuthorizeErrorKeys,
UserPermissionsFn,
PermissionKey
} from './authorization';
const SequenceActions = RestBindings.SequenceActions;
export class MySequence implements SequenceHandler {
constructor(
@Inject(SequenceActions.FIND_ROUTE) protected findRoute: FindRoute,
@Inject(SequenceActions.PARSE_PARAMS) protected parseParams: ParseParams,
@Inject(SequenceActions.INVOKE_METHOD) protected invoke: InvokeMethod,
@Inject(SequenceActions.SEND) public send: Send,
@Inject(SequenceActions.REJECT) public reject: Reject,
@Inject(AuthenticationBindings.AUTH_ACTION)
protected authenticateRequest: AuthenticateFn,
@Inject(AuthorizatonBindings.USER_PERMISSIONS)
protected fetchUserPermissons: UserPermissionsFn,
@Inject(AuthorizatonBindings.AUTHORIZE_ACTION)
protected checkAuthorization: AuthorizeFn,
) { }
async handle(context: RequestContext) {
try {
const { request, response } = context;
const route = this.findRoute(request);
const args = await this.parseParams(request, route);
// This is the important line added to the default sequence implementation
const authUser: AuthResponse = await this.authenticateRequest(request);
}
}
Current Behavior
Expected Behavior
See Reporting Issues for more tips on writing good issues
The text was updated successfully, but these errors were encountered: