If I build a provider hosted app for Office 365, how can I identify a customer and his environment?
What I mean: The app will be free from marketplace but will have a on app purchase subscription. Let's assume the following scenario: If customer will purchase the subscription he can do 10 tasks in my app. If he takes the free subscription he can do 1 task.
The customer should be able to install the app on many sites and the app can be accessed by any number of users. However I need to identify the customer in such a way that if the he installs the app on another site, the subscription he purchased will apply to him.
If the app is installed first on one site, where the customer does 3 tasks later if he installs the app on another site he can do the 7 left tasks (out of 10). So basically the app should identify the customer and his environment/tenant in office 365.
In on premise that will be easy using the SPFarm.Id but how can I identify the user and his tenant in Office 365?
Alright, I figured it out. The TenantId
is unique for every Office 365 instance as well for on premise.
If anybody interested. here is a piece of code to get the tenant id:
SharePointContext spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
Uri sharepointUrl = new Uri(spContext.SPHostUrl.AbsoluteUri.ToString());
string tId = TokenHelper.GetRealmFromTargetUrl(sharepointUrl).ToString();
That's it.
P.S. Credits goes to Vesa Juvonen from Microsoft for giving the right direction