microsoft / HealthClinic.biz

The samples contained in this repo are used to present an end-to-end demo scenario based on a fictitious B2B and multitenant system, named “HealthClinic.biz” that provides different websites, mobile apps, desktop apps, wearable apps, and services running on the latest Microsoft and open technologies aligned with announcements to showcase during the Connect(); 2015 event. The current published version works with Visual Studio 2015 Update 1 RC bits and ASP.NET 5.0 Beta 8. The final version used at Connect(); 2015 will be published soon.
http://aka.ms/Connect
MIT License
496 stars 292 forks source link

How is TenantId added to the requst header #4

Closed vnbaaij closed 2 years ago

vnbaaij commented 8 years ago

If I run the website from 01_Demos_ASPNET5.sln and go to the private area, I can see a TenentId in the request header. I can see this being used in MyHealth.API.AppExtensions.HttpRequestExtensions.GetTenant but I can not find where it is added to the header. Can you please explain where this is done?

stevejgordon commented 8 years ago

Looks like it's set in the BaseRequest within the CreateHttpClient() method

https://github.com/Microsoft/HealthClinic.biz/blob/f9397bdb18cf1996dec16d9668eebfe954bd4dcb/src/MyHealth.Client.Core/ServiceAgents/Base/BaseRequest.cs#L48

ibonilm commented 8 years ago

The mobile client apps send it every time that they make a web request.

In "src\MyHealth.Client.Core\AppSettings.cs" you can see the defaultTenandId that the native apps send.

In the same project, under the ServiceAgents folder, you have all the classes that make requests. All these classes use the BaseRequest.cs

In addition to this, in the server side, every user is always associated with one tenantId so after login the private area the webapp also knows the client´s tenantId that must use to retrieve the information from the database.

vnbaaij commented 8 years ago

I found the code @stevejgordon mentions but I do not see the MyHealth.Client.Core project referenced anywhere in the demo aspnet 5 solution. If I login to the private area the TenantId is read from the ApNetUsers table, right? But then I still don't understand how that value gets added to the request header if the Core code isn't referenced.

ibonilm commented 8 years ago

MyHealth.Client.Core project is only used by the mobile apps. If you open the solution 04_Demos_NativeXamarinApps.sln or 02_Demos_NativeMicrosoftApps.sln you will find it.

As you say, in the private area the tenantId is read from from the ApNetUsers table. The ApplicationUser class has this property.

The private are is a SPA that use Angular (src\MyHealth.Web\content\app\component)

For example, if you review the doctorService (src\MyHealth.Web\content\app\components\doctors\services) you will see that the SPA always send the Header with the tenantId.

function getDoctor(doctorId) { return getTenant().then((response) => { var tenantId = response.data; let url = /api/doctors/${doctorId}; return $http({ method: 'GET', url: url, headers: { TenantId: tenantId } }); }); }

vnbaaij commented 8 years ago

@ibonilm thanks for clarifying. I see now this is also done this way in app.js (which is only included in _LayoutPrivate and not in normal _Layout) in the DashboardService.

ibonilm commented 8 years ago

The app.js is a generated file. Each time you build the app or you run the default gulp task this file is updated.