Article 30 from 30 : Licensing your app

This post is article 30 from the 30 Articles App series for SharePoint

In this article, I will discuss about Licensing your SharePoint app on office store.

When you upload your app on the Office Store for publication, you can choose the terms of the license you want to offer, like offering your app for free, trial, or for purchase. Or your app can be acquired on a per-user or site basis.

SharePoint provides a licensing framework that lets you include code logic in your app to enforce whatever licensing restrictions you choose. For example, you can include code logic in your app that enables users to access certain app features if they have a paid license, but not if they have a trial license.

A user with a license for an app can use that app on any site for that particular SharePoint deployment. In general, for the purpose of app licenses, deployment is defined as the SharePoint farm for on-premises SharePoint installations, and the tenancy for SharePoint Online in Office 365. The app’s purchaser can manage the app license, assign those app licenses to other users within their deployment, and enable other users to manage the licenses. A user who is assigned an app license can access and use the app.

For apps for SharePoint that have a per-user license, each app license can be assigned to the specified number of SharePoint users. The app license applies only to the specified SharePoint deployment and the specified users.
For apps with a site license, that license is assigned to all users on that deployment automatically. You cannot programmatically assign app licenses.

App license query and validation process :
1. The user launches the app from within SharePoint.
2. This launches the app code in the cloud.
3. When the app needs to verify a user’s app license, it uses server-side code to query SharePoint, via the client object model, for the app license token.
4. It then passes that token to the Office Store verification service.
5. The verification service returns whether the license token is valid, and if it is, also returns the license properties.
6. The app can then take action, based on the validity of the license and its properties
OfLicAppSP

 

 

Finally, after you finish testing your app and are ready to move it to production, you need to add code to the license checks in your app so that the app no longer accepts test licenses.

Let’s validate app’s Validate the app license token in code:

Retrieving app license tokens using GetAppLicenseInformation :

productId = new Guid();
using(ClientContext ctx = new ClientContext(webUrl))
{
    ClientResult licensecollection = Microsoft.SharePoint.Client.Utilities.Utility.GetAppLicenseInformation(ctx, productId);
    ctx.ExecuteQuery();
}

Validating the app license token
After you retrieve the appropriate app license token, pass that token to the Office Store verification web service for validation. The verification service is located at the following URL: https://verificationservice.officeapps.live.com/ova/verificationagent.svc

The Office Store license verification web service also supports verifying app license tokens using REST calls. To verify an app license by using REST, use the following syntax:

https://verificationservice.officeapps.live.com/ova/verificationagent.svc/rest/verify?token=token

Where {token} is the app license token

For test app licenses, the IsTest property returns true and the IsValid property returns false.
This sample requires a reference to Microsoft.SharePoint.Client.Utilities, and a web service reference to the Office Store verification service.

retrieving app license tokens : GetAppLicenseInformation

//Get the license token XML from SharePoint.
this.rawToken = GetLicenseTokenFromSP(this.productId, this.clientcontext);

//Call the Office Store verification service.
VerifyLicenseToken(this.rawToken);

private string GetLicenseTokenFromSP(Guid productId, ClientContext clientContext)
{
    //Get the license from SharePoint.
    ClientResult licenseCollection = Utility.GetAppLicenseInformation(clientContext, productId);
    clientContext.Load(clientContext.Web);
    clientContext.ExecuteQuery();

    foreach (AppLicense license in licenseCollection.Value)
    {
        //Just get the first license token for now.
        rawLicenseToken = license.RawXMLLicenseToken;
        break;
    }
    return (rawLicenseToken);
}

private void VerifyLicenseToken(string rawLicenseToken)
{    
    if (string.IsNullOrEmpty(rawLicenseToken))
    {
        licVerifyEndPoint.Text = "There is no valid license for this user in SharePoint (OR) license cannot be obtained due to some error - check ULS.";
        return;
    }

    VerificationServiceClient service = null;
    VerifyEntitlementTokenResponse result = null;
    VerifyEntitlementTokenRequest request = new VerifyEntitlementTokenRequest();
    request.RawToken = rawLicenseToken;
    lblSPLicenseText.Text = System.Web.HttpUtility.HtmlEncode(request.RawToken);   

    try
    {
        service = new VerificationServiceClient();
        result = service.VerifyEntitlementToken(request);
    }
    catch (EndpointNotFoundException)
    {
        licVerifyEndPoint.Text = "Cannot access verification service endpoint";
    }
    catch (FaultException)
    {
        licVerifyEndPoint.Text = "Error: entitlement verification service is unavailable.";
    }
    catch (FaultException internalFault)
    {
        licVerifyEndPoint.Text = "Error: entitlement verification service failed. Details: " + internalFault.Detail.Message;
    }
    catch (Exception exception)
    {
        licVerifyEndPoint.Text = "Error: entitlement verification service failed. Details: " + exception;
    }

    if (result != null && result.AssetId !=null)
    {
        string licenseDetails = string.Format("Asset Id: {0}; Product Id: {1}; License Type: {2}; Is Valid: {3}; License Acquisition Date: {4}; License Expiry Date: {5}; IsExpired: {6}; IsTest: {7}; IsSiteLicense: {8}; Seats: {9}; TokenExpiryDate: {10}",
                result.AssetId, result.ProductId, result.EntitlementType, result.IsValid, result.EntitlementAcquisitionDate, result.EntitlementExpiryDate, result.IsExpired, result.IsTest, result.IsSiteLicense, result.Seats, result.TokenExpiryDate);

        if (result.EntitlementType.ToUpper() == "FREE")
        {
          //Allow basic functionality
        }
        else if (result.EntitlementType.ToUpper() == "PAID")
        {
          //Allow all functionality
        }
        else //trial
        {
          //Allow limited functionality
        }
    }
            else
    {
        licVerifyEndPoint.Text = "Verification service didn't return any results";
    }
}

Hope you have enjoyed this series !!

Advertisements

Article 29 from 30 : SPC14 summary on App Development

This post is article 29 from the 30 Articles App series for SharePoint

Future of Auto-hosted apps :

A few blogs from SPC14  say about AutoHosted Apps are being deprecated, This could be a rumor as Microsoft has not yet confirmed anything officially on this. If they are not being deprecated in near future, for how long they will be supported or when they may go from preview to fully supported is still not clear. As they are still in Preview, they should be avoided for Production design and recommended for only prototyping .

Some new Infographics for Apps:

These infographics can be downloaded from here . They give good and quick understanding on Why to build SharePoint apps?, App Concepts, App – hosting options, Data storage/access options etc.

New Office Web Widgets:

These experimental UI widgets were announced at SPC14 and are intended to help building apps for Office and SharePoint. The first release includes People Picker and the List View widgets. As per the Office dev team, these widgets are “experimental” and its primary goal is to collect feedback. They plan to release these controls for production use soon. Download it from NuGet Manager (search for Office Widgets) . Try it and send your feedback on UserVoice using the Office Web Widgets category.

NugetOfficeWidget

New Office 365 SDK for Android Preview:

Finally Microsoft is thinking openly ;). this sdk is built by  MS Open Tech and provides access to:

• Microsoft SharePoint Lists

• Microsoft SharePoint Files

• Microsoft Exchange Calendar

• Microsoft Exchange Contacts

• Microsoft Exchange Mail

The SDK is composed of three independent packages, so that you can import only the SDK that you need in your project.

  • office365-files-sdk [depends on office365-base-sdk]
  • office365-lists-sdk [depends on office365-base-sdk]
  • office365-mail-calendar-contact-sdk

For more info on this refer to http://msopentech.com/blog/2014/03/03/new-open-source-sdk-for-android-brings-office-365-apps-to-life/

 

External links to SPC14 Summary articles from SharePoint Community folks:

 

App webs are not working with mobile/tablet browser

Problem:

While trying to access appweb on mobile/tablet browser, I am getting a blank page with following error message:

[ Note : I am talking about app webs for SharePoint hosted apps for SharePoint 2013 and Office 365 -> SharePoint online;  I am not talking about office web apps just to clear the confusion. ]

The endpoint /sharepoint app1/_layouts/15/mobile/authn_dispatch.aspx is not accessible in the context of a sharepoint App.

20120912-112321.jpg

created a thread for this at http://social.msdn.microsoft.com/Forums/en-US/appsforsharepoint/thread/98ed1984-7748-41ff-bf04-387a15030168

Workaround

I did not figure out any workaround yet and don’t know whether there is any settings/way to get this working or this is by design?

I will update my findings once I get it sorted.

Please share your suggestion about this.

Update : [added on 13 sept 2012 00:58 AM]

It turns out that Mobile views are not supported for app webs for this *preview*; and so the problem is by design itself.

By turning on desktop view, I managed to work the app webs only with Android’s default browser.

No success with iOS even for desktop view.

I have not tested with Windows tablet yet but I guess it will work there..!!

According to Technet Article: Supported mobile device browsers in SharePoint 2013 Preview

Browsers supported by NAPA tools Office 365 preview

This is an initial Draft for my experience of NAPA (*preview *) tools with different browsers.

I have been using NAPA now and then since almost a month but only with IE9.

Today I decided to try out a few other browsers and below is the outcome for me.

IE (9.0.8112.16421): As I said, NAPA works like a charm….!! 🙂

Safari (5.1.7) : Unsupported Browser error as following

on web –> Unsupported browser

on iPad -> Unsupported browser (expected ..!!)

NAPA is truly brilliant idea and execution !! I would just dream of using NAPA on my iPad  if it worked in safari ?? OR Do I have to buy windows 8 tablet for that ?? 😛

20120907-010341.jpg

Firefox  (14.0.1) :  very slow… a long pause with the below message & then my browser crash…!! [tried this scenario about 3-4 times including restart ]

So I guess there is a support for Firefox but something is not working properly..!!

20120907-010333.jpg

Chrome (21.0.1180.89) :  NAPA works fine here too..!!

Please share your experience and views on this.

P.S. There may be update(s) on more findings about other  & above browsers !!

================= UPDATE : (added on 11 Sept 2012) : START  ================

Firefox 15.0.1: NAPA tools works absolutely fine.

I still have Firefox 14.0.1 on my other machine  (I may try to find error message or any log file later for it ) ….  But upgrading to the latest version for any browser should be the best practice.

I see NAPA as an opportunity to develop *anywhere* if you got the supported browser and internet of course 😛

As Mark says (referring to the comments for this post) NAPA will work with Windows 8 ( tablet ? ) with IE10 which is great !! ( you can experience IE10 RTM with Windows 8 or with windows server 2012, it’s not available for direct access otherwise at the moment  )

As I remember Mozilla has rejected the idea of crafting a version of Firefox for the iOS ( iPhone/iPad ) long time ago; and NAPA *preview* does not support safari itself … so I guess no NAPA on iPad; But for Android there is a version of Firefox and so I guess NAPA should work there..!!

Even though I am not a big fan of Safari web browser, I think making it work in apple & android tablets (*Usability*) would be definitely worth it.

I am not sure it is designed to work with tablets but I will give a try with Windows 8 tablet (don’t have one yet ) & firefox on Android. So stay tune for next update 🙂

Oh and don’t miss the comments for this post.

================ UPDATE : (added on 11 Sept 2012) : END ================

I have created a thread at microsoft forum for this : http://social.msdn.microsoft.com/Forums/en-US/appsforsharepoint/thread/b71e2900-abc6-443f-9aa4-4580aa5c6b45 ; Please give your feedback there to help making the product better.