Aspnetboilerplate: Change project template

Created on 4 Dec 2019  路  29Comments  路  Source: aspnetboilerplate/aspnetboilerplate

Hi
Iv'e downloaded project with Angular template which works pretty fine. However it has some classes like Tenant, Role, User ,... which are useless to me. I don't need them all. I just want to have my own entities but in Angular template. How can I easily get rid of all those classes? With less configurations.
Thanks In Advance

All 29 comments

These entities are useful for most developers, if you don't need them you can remove them manually,

You are right. but when I deleted them, I got the following Error.

Can't create component 'Abp.Localization.ApplicationLanguageManager' as it has dependencies to be satisfied.

'Abp.Localization.ApplicationLanguageManager' is waiting for the following dependencies:
- Service 'Abp.Domain.Repositories.IRepository`1[[Abp.Localization.ApplicationLanguage, Abp.Zero.Common, Version=4.9.0.0, Culture=neutral, PublicKeyToken=null]]' which was not registered.
- Service 'Abp.Configuration.SettingManager' which was registered but is also waiting for dependencies.
'Abp.Configuration.SettingManager' is waiting for the following dependencies:
- Service 'Abp.MultiTenancy.TenantStore' which was registered but is also waiting for dependencies.
'Abp.MultiTenancy.TenantStore' is waiting for the following dependencies:
- Service 'Abp.MultiTenancy.TenantCache`2[[InvoiceGenerator.MultiTenancy.Tenant, InvoiceGenerator.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[InvoiceGenerator.Authorization.Users.User, InvoiceGenerator.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' which was registered but is also waiting for dependencies.
'Abp.MultiTenancy.TenantCache`2[[InvoiceGenerator.MultiTenancy.Tenant, InvoiceGenerator.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[InvoiceGenerator.Authorization.Users.User, InvoiceGenerator.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' is waiting for the following dependencies:
- Service 'Abp.Domain.Repositories.IRepository`1[[InvoiceGenerator.MultiTenancy.Tenant, InvoiceGenerator.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' which was not registered.

Yes, there are still many dependencies in the project that need to be removed.

I suggest that you refer to the template code to manually create the project structure. This way you can decide which entities to use in your project from scratch. Do not use Abp.Zero related libraries in your project.

You can refer to this repository(although it is not the net core version) https://github.com/aspnetboilerplate/aspnetboilerplate-templates

Since we use Microservice Architecture, we have moved this (Tenant, Role, User ,...) into a separate project. So we don't need it within other projects.
When I unchecked this option:
__ Include login, register, user, role and tenant management pages,
the Angular Template disappeared. Is it possible to make it available when I uncheck the option above?! (for .NetCore Apps)

It doesn't seem to be available at the moment.

@abolfazlmohammadiseif unfortunately we don't have a plan to create such an option. You need to manually delete the classes you don't need and fix problems. After that, you can use it as your own template.

Thanks for helping @ismcagdas and @maliming .
I did it and created a project template manually which does not contain Tenant, user, role, ... .
The question is, I want my AppServices to check authentication of each request (I'm testing it using Postman). I added [AbpAuthorize] at the top of my service class. Then I sent a post request containing Bearer token. but I got "Error: Unauthorized".
Is there any other configuration that I miss considering?!

Could you share the full error message ?

{
    "result": null,
    "targetUrl": null,
    "success": false,
    "error": {
        "code": 0,
        "message": "Current user did not login to the application!",
        "details": null,
        "validationErrors": null
    },
    "unAuthorizedRequest": true,
    "__abp": true
}

Could you also share the error stack trace from server log?

This is a response from App within Swagger and Postman. This is not an error.

Code | Details
-- | --
401 Undocumented | Error: Unauthorized

Response body

{
  "result": null,
  "targetUrl": null,
  "success": false,
  "error": {
    "code": 0,
    "message": "Current user did not login to the application!",
    "details": null,
    "validationErrors": null
  },
  "unAuthorizedRequest": true,
  "__abp": true
}

Response headers

content-type: application/json; charset=utf-8  
date: Mon, 09 Dec 2019 06:02:03 GMT  
server: Kestrel  
transfer-encoding: chunked  
x-content-type-options: nosniff  
x-frame-options: SAMEORIGIN  
x-xss-protection: 1; mode=block

There must be error logs on server side log file. It is App_Data/Logs/Logs.txt file by default.

INFO  2019-12-09 10:03:11,640 [16   ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 POST https://localhost:5001/api/services/app/CustomerService/Create application/json-patch+json 154
WARN  2019-12-09 10:03:11,659 [16   ] calization.RequestLocalizationMiddleware - CookieRequestCultureProvider returned the following unsupported cultures 'tr'.
WARN  2019-12-09 10:03:11,681 [16   ] calization.RequestLocalizationMiddleware - CookieRequestCultureProvider returned the following unsupported UI Cultures 'tr'.
WARN  2019-12-09 10:03:11,703 [16   ] calization.RequestLocalizationMiddleware - AcceptLanguageHeaderRequestCultureProvider returned the following unsupported cultures 'en-US, en'.
WARN  2019-12-09 10:03:11,724 [16   ] calization.RequestLocalizationMiddleware - AcceptLanguageHeaderRequestCultureProvider returned the following unsupported UI Cultures 'en-US, en'.
INFO  2019-12-09 10:03:11,801 [16   ] ore.Mvc.Internal.ControllerActionInvoker - Route matched with {area = "app", action = "Create", controller = "CustomerService", page = ""}. Executing action InvoiceGenerator.Application.CustomerServices.CustomerService.Create (InvoiceGenerator.Application)
INFO  2019-12-09 10:03:12,294 [16   ] ore.Mvc.Internal.ControllerActionInvoker - Executing action method InvoiceGenerator.Application.CustomerServices.CustomerService.Create (InvoiceGenerator.Application) with arguments (InvoiceGenerator.Application.CustomerServices.Dto.CustomerInput) - Validation state: Valid
WARN  2019-12-09 10:03:12,352 [16   ] Abp.Auditing.SimpleLogAuditingStore      - AUDIT LOG: InvoiceGenerator.Application.CustomerServices.CustomerService.Create is executed by an anonymous user in 151 ms from ::1 IP address with exception: Current user did not login to the application!.
WARN  2019-12-09 10:03:12,391 [16   ] Mvc.ExceptionHandling.AbpExceptionFilter - Current user did not login to the application!
Abp.Authorization.AbpAuthorizationException: Current user did not login to the application!
   at Abp.Authorization.AuthorizationHelper.AuthorizeAsync(IEnumerable`1 authorizeAttributes) in D:\Github\aspnetboilerplate\src\Abp\Authorization\AuthorizationHelper.cs:line 42
   at Abp.Authorization.AuthorizationHelper.CheckPermissions(MethodInfo methodInfo, Type type) in D:\Github\aspnetboilerplate\src\Abp\Authorization\AuthorizationHelper.cs:line 107
   at Abp.Authorization.AuthorizationHelper.AuthorizeAsync(MethodInfo methodInfo, Type type) in D:\Github\aspnetboilerplate\src\Abp\Authorization\AuthorizationHelper.cs:line 56
   at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
--- End of stack trace from previous location where exception was thrown ---
   at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task)
   at Nito.AsyncEx.AsyncContext.Run(Func`1 action)
   at Abp.Authorization.AuthorizationInterceptor.Intercept(IInvocation invocation) in D:\Github\aspnetboilerplate\src\Abp\Authorization\AuthorizationInterceptor.cs:line 20
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformAsyncUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Github\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 78
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Castle.Proxies.CustomerServiceProxy.Create(CustomerInput input)
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.Extensions.Internal.ObjectMethodExecutor.ExecuteAsync(Object target, Object[] parameters)
   at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()
INFO  2019-12-09 10:03:12,538 [16   ] .Mvc.Infrastructure.ObjectResultExecutor - Executing ObjectResult, writing value of type 'Abp.Web.Models.AjaxResponse'.
INFO  2019-12-09 10:03:12,581 [16   ] ore.Mvc.Internal.ControllerActionInvoker - Executed action InvoiceGenerator.Application.CustomerServices.CustomerService.Create (InvoiceGenerator.Application) in 733.3627ms
INFO  2019-12-09 10:03:12,606 [16   ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 965.651ms 401 application/json; charset=utf-8

Could you also share your request headers ? You can check it on Chrome's network tab.

POST /api/services/app/CustomerService/Create HTTP/1.1
Host: localhost:5001
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IjVmOTcwMTMzMGVhY2QxOGVkYmEwNjNmZGUzY2ZlYjA5IiwidHlwIjoiSldUIn0.eyJuYmYiOjE1NzU4OTQ3ODcsImV4cCI6MTYwNjk5ODc4NywiaXNzIjoiaHR0cDovLzE5Mi4xNjguMi4zMjo0MDA1IiwiYXVkIjpbImh0dHA6Ly8xOTIuMTY4LjIuMzI6NDAwNS9yZXNvdXJjZXMiLCJkZWZhdWx0LWFwaSJdLCJjbGllbnRfaWQiOiJjbGllbnQiLCJzdWIiOiIyMDA4MCIsImF1dGhfdGltZSI6MTU3NTg5NDc4NiwiaWRwIjoibG9jYWwiLCJodHRwOi8vd3d3LmFzcG5ldGJvaWxlcnBsYXRlLmNvbS9pZGVudGl0eS9jbGFpbXMvdGVuYW50SWQiOiI2IiwidGVybWluYWxJZCI6WyIxMTFjZDUwYi03MDM5LTQwZGQtODhjMC1mNDYyN2VlNzczYzEiLCIgIl0sInNjb3BlIjpbImRlZmF1bHQtYXBpIl0sImFtciI6WyJwd2QiXX0.PqqFmKFAiBXJlAe6pYIxHzAcbDfFUpCTYkZOoxjnWvyydaM9vst6MVOef12OBzC_lknsuSz127ayCYa8H9Icca-U7N_awSup3C-wU1iv_CbP6kgik53BHDYqhRbL1QGiXLlAjs3fiigFHadYGiuQsxVjvAsATHE-I71Qsie4Lld7PnITpe4oeHIgKrRqR1Cg38J1MB806dZOe0CgL-HQfsXVVyQj_axkUXKoXEFyNi90yDOVexjWQkpddcVIZvhRM4VojHleNmHmaqNayQdNtgmEyekQuaEa_0gj4xEskQ3s3uZVJu4kUmElcNM82ueAP1zB-lCzX-aA8iEwblmvCw
User-Agent: PostmanRuntime/7.20.1
Accept: */*
Cache-Control: no-cache
Postman-Token: c6db926f-d3d0-492f-aa19-8ae4f7f0c874,a43ff6e6-cafd-495c-b875-573d5da1846b
Host: localhost:5001
Accept-Encoding: gzip, deflate
Content-Length: 202
Connection: keep-alive
cache-control: no-cache

{
  "id": 0,
  "name": "89898989898989898989",
  "mobile": "+898989898989",
  "email": "[email protected]",
  "address": "8989889",
  "cityCode": "8989898998",
  "description": "9999999999999"
}

It seems fine. Is your app multi tenant ? If so, is this a tenant user or host user ?

It is not multi tenant. It does not have Role, User, Tenant, ... . It is a simple (based on Angular Template) project which works fine Anonymously but has problem while using [AbpAuthorize] attribute at the top of service class.

If there are no users etc... how do you make authentication and authorization ? Did you also modified some other parts ?

I already have a specific authentication service that takes care of login process an gives a separate token to each request. So there is no need to have User, Role, ... classes in all microservices.
For better understanding, I can send you the whole solution.
So just give me your Email address.

@abolfazlmohammadiseif sorry for the late reply. The error is thrown here https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Authorization/AuthorizationHelper.cs#L40. And the related userId is retrieved from here https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Runtime/Session/ClaimsAbpSession.cs#L17.

Is it possible for you to share a sample token via email ?

It's Ok @ismcagdas . I can send the project via Email.

Hi @ismcagdas . How can I send my code? By Email?
( by the way, Happy New Year :) )

Thanks @abolfazlmohammadiseif 馃槃 . For now the token is enough. You can send sample token to [email protected]. I will check it.

Hi @ismcagdas I've uploaded the project Here in GitHub.
I think some configurations are incorrect.
Although I provide Bearer token, I get the following error.

{
  "result": null,
  "targetUrl": null,
  "success": false,
  "error": {
    "code": 0,
    "message": "Current user did not login to the application!",
    "details": null,
    "validationErrors": null
  },
  "unAuthorizedRequest": true,
  "__abp": true
}

You can check /api/services/app/InvoiceService/GetAll for example.

Hi @acjh I have a question here but I don't know how to fix it.
Would you please take a look at this question?
I provide token but still get the following error in postman.
"message": "Current user did not login to the application!",
and when I injected the ApplicationService in Controller and called its method within a WebApi, I got the fallowing error in Swagger:
InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found.
I already have a separate authentication microService that takes care of login process and gives a separate token to each request. So there is no need to have User, Role, ... classes in all microservices.

Your appsettings.json is malformed.

I modified it.
I think there is something wrong with Startup.cs but I don't know what it is.

How to reproduce?

I've updated the repository.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ahmedhassieb picture ahmedhassieb  路  26Comments

ktngoykalolo picture ktngoykalolo  路  55Comments

alexeynikitin picture alexeynikitin  路  27Comments

beriniwlew picture beriniwlew  路  31Comments

okezieokpara picture okezieokpara  路  59Comments