abpframework / abp

Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
https://abp.io
GNU Lesser General Public License v3.0
12.81k stars 3.41k forks source link

Issue with Tenant Configuration in BookStore-Angular-MongoDb Sample Project #19966

Open MehdiElMellali opened 4 months ago

MehdiElMellali commented 4 months ago

Is there an existing issue for this?

Description

I'm currently working on the BookStore-Angular-MongoDb sample project. I'm trying to implement tenant functionality, but I'm encountering an issue with CurrentTenant.Id. Specifically, CurrentTenant.Id is returning null in my setup.

Here's a screenshot of the issue I'm facing: image

Reproduction Steps

Cloned the repository and followed the setup instructions. Verified that the project is running correctly without tenant-specific code. Attempted to use CurrentTenant.Id, but it returned null.

Expected behavior

No response

Actual behavior

Do I need to configure anything specific in the project to ensure that CurrentTenant.Id is populated correctly? How can I add the tenant ID to the token? Below is an example of the current token I'm using: { "sub": "a966ae1c-ef07-d11b-69e7-3a12ed60a87c", "unique_name": "user", "preferred_username": "user", "email": "user@example.com", "email_verified": "False", "phone_number_verified": "False", "oi_prst": "BookStore_App", "client_id": "BookStore_App", "oi_tkn_id": "30ddcebc-d29c-b33e-03e4-3a12ed6456f6", "jti": "cfc15f79-d8ba-4101-a9e0-24c3dbf5e479", "iss": "https://localhost:44367/", "exp": 1717373398, "iat": 1717369798 }

I would greatly appreciate any guidance or examples on how to properly configure the project to use CurrentTenant.Id and how to include the tenant ID in the token.

Thank you!

Regression?

No response

Known Workarounds

No response

Version

8

User Interface

Angular

Database Provider

EF Core (Default)

Tiered or separate authentication server

None (Default)

Operation System

Windows (Default)

Other information

No response

maliming commented 4 months ago

hi

There is no tenantid claim in your current principal. So it will be null.

You can try to switch the current tenant on the login page. and then login a user who belong a tenant.

https://docs.abp.io/en/abp/latest/Multi-Tenancy

MehdiElMellali commented 4 months ago

@maliming I have created users who belong to a tenant and have manually added tenants in the database. However, I'm not sure how to add the tenant ID to the claims. Could you provide guidance on how to include the tenant ID in the claims for these users?

and TenantId from user alson NULL (I have created users who belong to a tenant) image

Thank you!

MehdiElMellali commented 4 months ago

@maliming Please can you check the code and find attached the project.zip file aspnet-core.zip

Thank you!