0

I have developped a Cumulocity (C8Y) application. This application can be onboarded or not according to the C8Y tenant.

With other words, my C8Y application can run under different C8Y tenant. My C8Y application needs to know what is the tenant name of the logged-in user. Indeed, my C8Y application needs to communicate with an external application and has to provide the tenant name of the logged-in user.

NOTE : Afaik, there are two solutions to manage the C8Y tenants : solution 1. the url is tenant-specific i.e. http://.domain solution 2. the logged-in user is tenant specific and there is an unique url i.e. : - unique url : http://domain - user name : tenant id/user name

I am using the solution 2

2 Answers2

1

You can use the following API

GET /tenant/currentTenant

This will return the tenantId as well if you cannot extract it from just knowing the domain.

TyrManuZ
  • 2,039
  • 1
  • 14
  • 23
  • I have already used the GET /tenant/currentName. This operation gives the tenant name of the API user and not of the logged-in user – Paul Claverie Apr 09 '18 at 14:49
  • You can use /user/currentUser which will give you the full user details of the user that is doing this request – TyrManuZ Apr 11 '18 at 02:00
  • - /tenant/currentTenant gives the tenant name of the user who is included in the auth header of the http request - /user/currentUser gives the user name of the user who is included in the auth header of the http request The requirement is NOT to know information about the auth header but to know the information (tenant name & user name) about the logged-in user – Paul Claverie Apr 11 '18 at 06:22
  • Maybe, the solution is not based on the C8Y rest api usage. Is the logged-in user stored in a javascript variable or in a jsp? With other words, our C8Y application has to get the logged-in user which is displayed on the top at right in the C8Y UI – Paul Claverie Apr 11 '18 at 06:36
  • You can use the current() function from http://resources.cumulocity.com/documentation/jssdk/latest/#/api/c8y.core.service:c8yUser. In the end it will just call /user/currentUser. There is nothing like a user session or something like this. The logged-in user is the one that you are doing the requests with. – TyrManuZ Apr 12 '18 at 08:32
0

on Cumulocity the tenant name is the same for each user on a specific tenant. So to know on which tenant a user is logged into you should use solution 1 as all Cumulocity tenants look like .cumulocity.com.

  • My customer enforces me to use the solution 2. Via the solution 2, is there a C8Y function or C8Y rest api to let my C8Y application know who is the logged-in user. Note : if my C8Y application know ghe looged-in user, it would be able to extract the tenant id from the string / – Paul Claverie Apr 09 '18 at 10:32