Tuesday, 31 October 2017

4 Reasons Why AppExchange is More Powerful than ever Before!

Salesforce AppExchange, the #1 cloud marketplace, is a proven ecosystem of apps with millions of installs and thousands of customer reviews to help you find the best match for your business. As of 24th Oct 2017, Salesforce went for a complete revamp of the AppExchange UI. What this essentially means is that while AppExchange just a Marketplace for Applications earlier, which then went on to list Components too, it now lists Lightning Data and Lightning Bolt as well!


1. Salesforce Welcomes New members to the AppExchange Family

Salesforce has added 2 new members to the AppExchange family: Lightning Data and Lightning Bolt.

Lightning Data gives access to specialized data set which customers can buy, leading to a definite boost for their Sales and Marketing teams with pre-integrated, approved and scalable data solutions.


Lightning Bolt Solutions allow Partners to publish pre-built templates which can be used by customers to create next-gen communities and portals.




2. Everything is just 2 clicks Away!

The Salesforce UX team has worked really hard to make customers’ life easy. Earlier, users needed to click a minimum of 3-4 clicks for getting information about the App provider. Now, everything is just 2 clicks away, with  all the required information about the Application and App vendor available on a single tab, with reviews moved to a separate tab.

Application Listing Old UI

Application Listing New UI



3. A Smarter Search

In another good example of UX, AppExchange now saves your recent search items to make it available for later use, helping the customers who may have searched for a lot of applications.



4. Salesforce’s other Marketplaces are also under same umbrella

Earlier, Salesforce had different Marketplaces for Heroku elements, Marketing Cloud apps and so on. With the recent revamp, you can find other apps like Heroku elements, HubExchange (Marketplace for Marketing cloud applications), Link Marketplace (Marketplace for eCommerce Solutions) on the same integrated platform called AppExchange.



Salesforce has taken cognizance of all customer pain points and turned AppExchange into an all-encompassing, powerful and customer-oriented Marketplace. A detailed description of all new AppExchange features can be found here.




Written by Purushottam Bhaigade, Technical Lead at Eternus Solutions
Read More »

Monday, 30 October 2017

AppExchange 2.0 Secrets Unleashed for Salesforce Partners

Had Marc Benioff not gifted the phrase “App Store” to his mentor and friend, the late Steve Jobs, the AppExchange would have been known as the Salesforce App Store today.

With 4000+ solutions, 5 million+ app installs and 87% of Salesforce customers using AppExchange apps, the 2005 born, 11-year-old AppExchange has come a long way from merely being an apps listing service to a powerful community of business apps, customers and partners. Its recent makeover unveiled on 24th Oct, 2017, therefore, is nothing short of a rebirth, making it 'The AppExchange 2.0'.

The Salesforce partner ecosystem is one of the pillars and the largest contributors fueling the Salesforce economy, which is forecasted by IDC to drive 3.3 million jobs and in excess of $859 billion in revenue by 2022. Hence, awareness of how this Appexchange makeover empowers Salesforce Partners by marrying their interests, is of essence.


Defining App USPs Was Never Significant Than Now

Powered with an intelligent search which recommends all the relevant and similar apps to the customers, the new Appexchange provides them with a la carte menu of apps to choose from in a particular category. For e.g. when I search the term “documents”, the search results consist of all relevant apps, consultants, industry solutions around document generation or a similar feature.


This makes it imperative that ISV partners clearly define their application’s unique selling point, from that of your competitors, thus enabling customers to make informed buying decisions.


Tighten Loose Industry Specific Nuts With Lightning BOLTS

With Lightning Bolts, ISV Partners now have the power to package industry specific process flows, apps and lightning components as predefined solution templates, leading to faster deployments and go to market, without having to reinvent the wheel. A great example of this is a promotion management and communications Lightning Bolt solution for the Retail sector offered by Appirio.


This enables ISV Partners to carve their niche within an industry vertical, and helps them emerge and be recognized as industry leaders rather than just application providers.


Brand Your Product And Industry Expertise

AppExchange 2.0 brings in two important perspectives of categorizing solutions with their relevance to industry vertical using Industry collections, and with relevance to a specific Salesforce product using Product Collections. This provides Salesforce Partners, with an opportunity of being recognized as not only an expert in the relevant industry vertical, but also, in a respective Salesforce product umbrella.


For e.g. Product collections for Sales Cloud provides solutions addressing A to Z needs of the sales process, starting from unlocking sales channel to driving sales rep productivity.




Shorter Application Issue Resolution Cycles

Dealing with technically aware and well informed customers is a dream come true for product support reps and AppExchange 2.0 has made this a reality. AppExchange 2.0 not only provides a wide array of apps to thee Application users to choose from, but also goes a step ahead and empowers them through recommendations of relevant and applicable Trailhead self-learning modules.

This inevitably results in a smarter and cognizant generation of application users along with shortened issue resolution cycles.


Show Them The Money

Business plans sculpt the blue print of your apps by pushing Salesforce partners to ponder over key aspects such as target audience, potential revenue forecast, customer pipeline etc. thus enabling you to build an awesome business app.

As it is rightly said “Don’t just build a product, build a business around a solution that solves business problems” and staying true to this, AppExchange 2.0 empowers partners to not just think about the application architecture and design, but also a sustainable long term business plan, blending it beautifully within the listing setup of the Partner Community.


Last but not the least, the Appexchange makeover is a force to reckon with, which complemented with the powerful partner ecosystem, will prove a game changer in times to come.




Written by Jigar Shah, Enterprise Solution Architect at Eternus Solutions
Read More »

Tuesday, 17 October 2017

Understanding – Time to First Byte



Introduction


I faced slow website loading in a project and I am sure many of you must have faced the same. Now-a-days, people are worried about responsiveness of web server and speed of their websites. There are many reasons as to why your website might be slow! Typically, the most common reasons are inappropriate hardware configuration, incorrect coding practises, slow internet connection and so on. Apart from these, there is an overlooked but highly important factor that degrades the performance of your site and that is TTFB - Time to First Byte.


What is TTFB?


TTFB – Time To First Byte, is a metric to measure responsiveness of web server and speed of website. In simpler words, it is the time any browser has to wait for the first byte to be received. TTFB is not the only metric to measure the speed of your site. In spite of this it cannot be overlooked.

Organizations make use of TTFB to identify the weak points like speed of their website when they make http request. By identifying the weak points, they know whether it is a server configuration issue or an application issue etc.

Following is the illustration of TTFB seen in Chrome Developer Tools. There are also various other components in the image below starting sequentially is Request Sent, TTFB and Content Download of the website.

The Request sent to the server took 0.16 ms which is acceptable. Then there is a waiting time for the content to be downloaded. This waiting time is TTFB where we receive the first byte of the response. So TTFB is the first thing that we have received before the content is downloaded and TTFB for current site request is 2.85 seconds which is huge. Finally, the content of website like CSS, images and scripts and so on, are downloaded in 8.55 ms which is also acceptable. So we can easily understand from the image below that TTFB is the first byte that we receive even before the content is downloaded.


Tools for Testing TTFB


There are various tools available online to test the performance of your site. Testing the performance of your site is indirectly, nothing but measuring TTFB. Following are the free tools you can use to measure TTFB of your site:-
  1. WebPageTest
  2. Google Chrome – Developer Tools (this is recommended as it is default integrated with Google Chrome Browser)
  3. Pingdom
  4. KeyCDN

TTFB Impacted by/Causes of High TTFB


TTFB is impacted by many factors, there are reasons as to why your TTFB is high. Following are some of those reasons:-

1. Server Configuration
The first thing that hits us is inappropriate server configuration. Off course, inappropriate server configuration is one of the major reasons to high TTFB. If your server configuration is inappropriate it will affect the performance of your site. It can make the processing of any request slow which will in turn result in high TTFB and the performance of your site will degrade.

2. High CPU Usage
Even if your server configuration is good your site might perform slow. Reasons to high TTFB are innumerable, one of which is High CPU Usage. If the CPU usage of your server is high it might degrade the performance of your site. Your server will not be able to process your requests quickly.


3. Slow Database Request
Slow Database Request is also one main reason for slow performance of your site. If your database is not structured well(indexes) or your query is not well-formed, then it will for sure add some delay in execution and will result in slower performance of your site.

4. Inefficient code on server
One of the main reason for slow performance of your site is inefficient code. Inefficient code will slow down the execution of your application and also will ultimately increase the CPU usage which will result in slow performance of your site. So, it is recommended that you always use best coding practises for your application.


Effect of TTFB

TTFB strongly affects the search ranking of your site. If TTFB of your site is high then it will affect the ranking of your site by not listing it at the top when searched. So the ranking of your site is directly linked to TTFB of your site. Though TTFB is not the only metric of low ranking of your site, however, it plays a major role in ranking of your site.

Improving TTFB


Improving TTFB can greatly help you increase the performance and speed of your site. Improving TTFB is nothing but reducing the TTFB number i.e. if the TTFB of your site is 4 seconds then you can improve TTFB of your site to 1 second. Following are the ways you can improve TTFB of your site:-

1. Improve your server configuration
Good server configuration can ultimately increase the speed of your site. It will automatically perform faster in serving end user’s request and also can speed your database queries and application processing. You can add a load balancer to improve the performance of your site. Load balancer balances the requests received by end user when actual server is running out of memory. Your load balancer server will just perform like your actual server.

2. Implementing CDN
A CDN is a spread over network which delivers html pages and other web contents from the server to end user based on their geographical locations, the origin of the web page and content delivery server. Implementing a CDN is a really good idea to improvise the performance of your site. Fetching everything from your hosting server over the network can cause latency and will reduce the performance of your site. Thus implementing a CDN will really be helpful if the request is from where the CDN server is present and will not cause any network latency. Ultimately improving the performance of your site.

3. Caching 
Caching is a process of temporarily storing the data you request in cache. For example, the files you automatically request by looking at a Web page are stored on your hard disk in a cache subdirectory under the directory for your browser. When you return to a page you've recently looked at, the browser can get those files from the cache rather than the original server, saving you time and saving the network the burden of additional traffic. Caching is a good technique to increase the performance of your site. It is mainly used for static content of your site. It will also reduce the network latency of your requests, thus increasing the speed and performance of the website.



Conclusion

TTFB is an important metric in measuring the performance of your site. Above mentioned measures to improve TTFB are fairly simple to implement. A TTFB time of 500 ms or less is recommended.



Written by Rohit Sevaramani, Tech Lead (MCP) at Eternus Solutions
Read More »

Sunday, 13 November 2016

10 Things I love About Wave Analytics

If your company has huge amount of data and your top management needs actionable reports for turnover, growth, revenue etc., you would need a robust and scalable BI tool or provide these answers quickly. This is where Salesforce Wave Analytics has emerged as a crucial player.

Sample Wave Dashboard (Image source: elibrumbaugh.com)

Built on the Wave platform, Salesforce Analytics Cloud is much more than simple Business Intelligence. Organizations can build their own BI applications and make important data-driven decisions, enabling quick actions and smarter connectivity.

How is Wave different from Traditional BI?

Every BI application has a different architecture. The speed with which your BI application gives you the required information is a key factor in its usability, which in turn depends on how you get the data from source system, how you store the data, how you query the data and how you present the data on the UI.

Image source: Salesforce Wave Training

Most of the traditional BIs need to be installed in the client’s machine and store data in the same manner as a relational database would. In almost all those traditional BI tools, queries are complex and time consuming, and these BI tools are often found to be lacking in providing complex insights that is often required by the business.

Compared to traditional BI tools, Wave scores on a lot of fronts. Not only does it disseminate required information at a faster speed, it can get the data from Salesforce, CSV files and partners like Jitterbit, Informatica, Talend, Mulesoft, Boomi, Snaplogic etc. Additionally, Wave is schema free and stores the data in the form of compressed .json. To top it all, Wave is 100% mobile.

Why Wave Analytics?

A pertinent question that arises is the need for Wave Analytics if Salesforce already has inbuilt reports and dashboards. The answer lies in Wave’s capabilities that extend beyond Salesforce reports and dashboards. When compared to Wave, Salesforce dashboards have a lot of limitations, like the inability to create a dashboard using external systems data, inability to get the required insights from the data, Dashboards on Salesforce1 are read-only and are not available to edit.


Which brings me to the 10 most significant reasons why I absolutely love Wave!
  1. Search Based Technology: Wave can get the data from Salesforce, csv, external tools like Informatica, Talend, Jitterbit etc. Wave runs the data flow and wave parser converts all the incoming data into a compressed structure and stores the data in the form of json, which is only the plain text data in the form of key value pairs and a very light weight form of data. With minimal efforts, Wave can search on these key pairs and get the insights from the data.
  2. Schema free non-relational database: Unlike traditional BI tools, the Wave engine does not store the data in the form of a relational database because the database brings quite a few limitations along with it. The database could have repeated values, join operations in schema are always expensive and a linear size expansion makes it ever so difficult to be optimized for read and write operations.  A schema-free Wave stores the data in a compressed format using a key value pair.

    Image source: Salesforce Wave Training

  3. Inverted Index: Speed is a key factor for any successful BI application and it depends on multiple factors like hardware, chosen architecture, query, search operations, etc.



    An indexing technique is used in traditional BI tools. However, if you have a large amount of data and it is increasing rapidly over time, your index also gets increased. You would end up requiring indexes for the indexes, meaning if you use indexing for large datasets, it can affect the speed. Wave has implemented the concept of an inverted index. Just as a book’s last pages has the information on keywords and page numbers on which that keyword has appeared (inverted index), Wave would also store the data in the form of a key value pair.
  4. Loading External data to Analytics cloud:  When stakeholders decide on a BI tool, they consider a few aspects like the type of data within their systems and the compatibility between their systems and the BI tool.  Wave overcomes all these problems. Wave engine is intelligent enough to get the data from Salesforce as well as csv file and partners like Jitterbit, Informatica, Talend, Mulesoft, Boomi, Snaplogic etc.

    Image source: Salesforce


  5. Trusted and secure architecture: Wave being a Salesforce product essentially means that all the security measures in Salesforce hold true for Wave as well. Additionally, Wave also has App level security, field level securities, row level securities to ensure authorized access.

    Image source: Salesforce


  6. Mobile First Design: The top level management of every company needs relevant dashboards and it is additionally useful if they can access the same on the go. Wave enabling the users to create, update and edit dashboards on the fly, with a beautiful and responsive UI for some added zing and It is also available on Apple watches.

    Image source: techcrunch.com


  7. Customized business apps: There are some predesigned wave apps readily available on the AppExchange Like Sales Wave, eCommAnalytics, FinancialForce etc. User can install these wave apps, and get instant answers to their questions.
  8. Visualforce Integration: Yes, you read that right! Wave dashboard can be a part of your Visualforce page by using <wave:dashboard> attribute in the Visualforce page, enabling you to transfer the power of wave to your Visualforce page.
  9. Display Dashboards in Salesforce sObject page layout: You can display Wave dashboards within your Salesforce page layout and display the user specific records on that dashboard.
  10. Can perform actions in Salesforce: Even though Wave is altogether a different platform, it has the power to perform certain actions directly on Salesforce objects, like creation of a task or event, logging a call, creation of a case or updating records etc.
Wave has a killer UI to top it all, ensuring that you are truly able to see and realize the power of analytics that is packed into it. Analytics was never this powerful and beautiful before!



Written by Anand Shinde, Salesforce Developer at Eternus Solutions
Read More »

Monday, 7 November 2016

Managing Different Perspectives of the Developer Console

Being a rookie Salesforce.com developer, I often wondered if System.debug statements were the only way to find out where my superbly written code was breaking. Much to my dismay, I was often all at sea, trying to find out the actual cause of the issue only through execution debug logs provided and without actually editing the code. Wasn’t there a better way, I thought? That’s when I stumbled upon the inbuilt features of the developer console.

The developer console basically provides a convenient set of tools for efficiently tracking down logical issues. A perspective is a predefined arrangement of panels in the developer console log inspector. The developer console has a set of tools that enables the developers to track what exactly is happening down there in the hood. These tools are grouped together by default and presented to us in the form of a perspective.

To view all the default perspectives, simply click on debug → Perspective Manager in the developer console.

Out of these predefined perspectives, one of the most helpful panel is the Execution Overview panel which is a part of Analysis perspective.

The Execution Overview panel consists of four tabs.

Save Order Tab

Let’s consider a case where you are new to a project and are unable to gauge the exact flow of execution. Alternatively, you might be familiar with the project but observing some weird changes. You might find that some fields or actions are affected only if the code is executing recursively but for some reasons you are unable to determine where and what is making the code run into recursion? Another possible scenario could be where you are unable to determine which validation rule or which workflow rules are fired or is it a custom workflow or validation that is causing an issue to occur?

For all such scenarios, the immediate solution could be to direct to the Save Order tab which is a part of Execution Overview panel.

The Save Order tab provides an overview of all the actions that are performed during a DML operation in a beautiful color-coded format. Not only is it color coded, but it also displays all the actions in a intuitive sequence diagram. You no longer need to scratch your head in determining whether the validation rule ran first or the trigger; the Save Order tab has got it all covered.

This tab follows a color code format for better and fast understanding for the end user.

It states:

Colour
Actions
Before trigger
After Trigger
Validation Rule
Assignment Rule
Workflow Rule

Once you click on the validation rules, you are directed to the actual validation rule in the execution log panel where you are able to view its actual detail.




Executed Units Tab

As a part of the Salesforce development, we might have faced a few exceptional scenarios we are usually scared of, but which need to be tackled nonetheless; such as the CPU time limit exceeded exception or the Heap size Limit exceeded exception. There might have been cases where you were unable to figure out the total number of rows affected due to the DML action.

The Executed Units tab, which is a part of the Execution Overview panel, helps you find the answers to all these queries very easily.

It displays the system resources used by each item in the process. Additionally, there are various buttons:  Method, Queries, Workflows, callouts, DML, validations, triggers, Pages; at the bottom of the tab which can be used to filter out information by item type.

In the Execution Units tab, we have following columns:

#
Column
Description
1
What The what column includes the various operations known as process items that are executed in particular execution.
The different process items that are included are as follows:
  • Method
  • Queries
  • Workflow
  • Callouts
  • DML
  • Validations
  • Triggers
  • Pages
2
Name For each of the process included above, it gives the name for it.  e.g.
If “method” is included in the “what” column the name of the method that is executed is displayed in the name column accordingly.
3
Sum If the process is executed more than once then the sum of duration for that particular execution is calculated in milliseconds.
4
Avg The Avg column displays the average duration (in milliseconds) taken for the process to be executed. It is calculated based on the formula (Sum/Count).
5
Max If the particular process is called more than once, the maximum duration (in milliseconds) taken for execution among all those executed processes is included in max column.
One of the use case where the information displayed in this column would help you, is to solve CPU time limit exceeded exception.
6
Min If the particular process is called more than once the minimum duration (in milliseconds) taken for execution among all those executed processes is included in min column.
7
Count Number of times a particular process was called during its execution.
8
Heap Amount of space the process took on the heap is specified in bytes.
e.g. Heap size limit exceeded exception would be traced much faster by observing information listed in this column.
9
Query Type Type of query. Possible values are:
  • SOQL
  • SOSL
10
Sum rows Sum of all records changed during the execution of particular process.
11
Avg rows Average number of records changed during the execution of particular process.
12
Max rows Maximum number of records changed during the execution of particular process. For eg: The Max rows count would help you to solve SOQL Limit exceeded exception by determining the exact process which has caused the exception.
13
Min rows Minimum number of records changed during the execution of particular process.



So many tools in such a small window! Magic, thy name is Developer Console! Guess what, the fairy tale doesn’t end here; there are some more unsung features that prove to be a great boon to the developers.  But that is for another day, as I shall be covering them in my next blogs. Till then, let the magic of Developer Console make life a smooth ride for you!



References :



Written by Kaajal Bhawale, Salesforce Developer at Eternus Solutions
Read More »

Tuesday, 9 August 2016

How to Generate a PDF from your Visualforce Pages: Going Beyond ‘renderAs’

As a Salesforce developer, your customer might often need you to convert his Visualforce page into a PDF format. That is simple enough, right? All you need to do is to use the “renderAs” attribute on the Visualforce page and you are done! Hold on! There’s more to this than what meets the eye.

Imagine you have a similar requirement but instead, this time with a page using Lightning tools which, on one hand will save you from archaic UI, enabling you to use lots of great charting options for that perfect GUI that your client craves for, but taking away the ease of generating a PDF from the same page with a simple usage of “renderAs”. What will you do now?

In this blog post, I will take you through a simple workaround to ease your problems using jQuery library of jsPDF. I have used jsPDF, keeping all the graphs and tables inside the <div></div> tag which was later on converted into a base64 image using canvas library and then re-writing the same content in the pdf output.

Given below are the steps to follow so as to enable creation of pdf even with complex pages.
  1. Download the following jQuery files and upload them as static resources within Salesforce. Add them to your Visualforce page as well
  2. Cover your design portion (the portion that is complex with graphical charts and long tables) within div-tag
  3. Add the code given below in your apex class. The function getImgUrl enables you to generate a base64 image URL of the div portion (from step 2)
  4. The code snippet given below will add your base64 encoded image URL into your pdf file

Once you execute this code, your PDF will contain the graph and table that you wanted to include within it. Your problem ends here.

Does it?

There is still a critical scenario that can ruin all the hard work that you did above. What if the size of the image is more than the size of the PDF? Wouldn’t this approach cause the image to break and not be displayed properly in the PDF format?

Don’t worry! All is not lost.

In order to work around the above scenario, you need to know the height of your generated image. To get this, you need to convert your image into a base64 string. Now set the minimum height of your pdf page (in my example, I am setting it to 1760, normally approximated to its standard size).

Now you have the height of your pdf as well as the image. Divide the image height with that of your pdf height and the ratio you get will give you the number of pages that your content (in the form of image) intends to span across the psf. Now you need to iterate over the no. of pages and keep adding the image into your pdf. The code below will help you achieve the same.


For more details on how this works, check out this link https://pdf-generate-developer-edition.ap2.force.com/

Happy Coding..!!!

Reference Link: https://parall.ax/products/jspdf 





Written by Siddhraj Atodaria, Salesforce Developer at Eternus Solutions
Read More »

Monday, 11 July 2016

Generate OAuth Authorization Token using OWIN with SharePoint

As a SharePoint developer, you are aware that SharePoint provides OAuth Authorization services to generate access token from SharePoint using its own prerequisites. However, this approach has its own limitations. We can generate same token without using OAuth Authorization provided by SharePoint. In this blog, I will take you through the process of generation of Bearer Token for a custom third party client application to authenticate and authorize with SharePoint and perform operations on SharePoint data using the generated access token.

Let's first know how a SharePoint token works

When a user signs in to SharePoint, the user's security token is validated. The token is issued by an identity provider. SharePoint supports several kinds of user authentication.  For more information on this, see Authentication, authorization, and security in SharePoint 2013.

In SharePoint 2013, we can create apps using SharePoint Add–Ins. These Add-Ins are also required to be authenticated and authorized with SharePoint. These Add-ins can be authenticated and authorized in several different ways. For more information on this, see Three authorization systems for SharePoint Add-ins.

As mentioned, for all the given authorization systems to get access tokens for logged in user, either we need to create a high trust using certificates or we need to register with Microsoft Azure Access Control Service (ACS). In both these scenarios, our custom site requires to be configured with secure access i.e. HTTPS protocol with high trust certificates.

So, the workaround to create access tokens from SharePoint site other than the options provided by Microsoft is creating a custom ASP.Net Web API using OWIN.

What is OWIN

OWIN is an Open Web Interface for .Net which acts as a middleware OAuth 2.0 authorization server between SharePoint site and a third party client application. OWIN defines a standard interface between .NET web servers and web applications.

Using ASP.Net Web API and OWIN, we can authenticate and authorize users with SharePoint site and generate access token for this user, and further use this access token for CRUD operations on SharePoint site using SharePoint REST API's by passing the "Bearer" access token in the headers of the query.

Authorization Methods in SharePoint

To perform CRUD operations on SharePoint content using SharePoint REST APIs, there are different ways to pass authorization:
  1. System.Net.CredentialCache.DefaultCredentials:
    The DefaultCredentials property applies only to NTLM, negotiate, and Kerberos-based authentication.

    DefaultCredentials represents the system credentials for the current security context in which the application is running. For a client-side application, these are usually the Windows credentials (username, password, and domain) of the user running the application. For ASP.NET applications, the default credentials are the user credentials of the logged-in user, or the user being impersonated.
  2. System.Net.NetworkCredential(username, password, domain):
    The NetworkCredential class is a base class that supplies credentials in password-based authentication schemes such as basic, digest, NTLM, and Kerberos.

    This class does not support public key-based authentication methods such as Secure Sockets Layer (SSL) client authentication.
  3. Bearer Token:
    Tokens are issued to clients by an authorization server with the approval of the resource owner. The client uses the access token to access the protected resources hosted by the resource server. This specification describes how to make protected resource requests when the OAuth access token is a bearer token.
The First option stated above cannot be used in a custom third party client application as it does not understand the default credentials. The Second option stated above passes username, password and the domain in which the user needs to be authorized, which will cause a security threat as the client application will need to store user's password and send it whenever required.

SharePoint 2013 uses OAuth 2.0 Authorization framework for Bearer Token usage in SharePoint Add-Ins. Once the access token is generated, the custom application can use this token to perform CRUD operations on SharePoint 2013 content using SharePoint REST APIs. This token is sent through headers from the code that is running on a browser client. You will not need access token if you are making this call from a SharePoint hosted app add-in.

In a similar way, we can generate access token in ASP.Net Web API and OWIN by passing in the username and password for the first time. Once the access token is generated, we can use this token for CRUD operation for SharePoint REST APIs.

How to Generate Access Token using OWIN

Below are the steps to generate access token using OWIN
  1. Create a new empty ASP.Net Web Application Project. Select "Web API" check box under "Add folders for core references for" tab. In the Authentication, select "No Authentication".

  2. Create a class "Startup.cs" in the project at root level which will be required for OWIN.
  3. Install the required OWIN components in the solution using Nuget Package
    • Install-Package Microsoft.Owin.Host.SystemWeb
    • Install-Package Microsoft.Owin.Security
    • Install-Package Microsoft.AspNet.Identity.Owin
    The above commands will install the OWIN Hosting infrastructure as shown below

  4. Every OWIN Application has a startup class where you specify components for the application pipeline. There are different ways you can connect your startup class with the runtime, depending on the hosting model you choose (OwinHost, IIS, and IIS-Express).

    OwinStartup Attribute: This is the approach most developers will take to specify the startup class. The following attribute will set the startup class to the TestStartup class in the StartupDemo namespace.
  5. Add Configuration method with IAppBuilder parameter
  6. Configure OAuth Authorization for application which will be authenticated and authorized with a SharePoint site and Domain.
  7. Now override the methods ValidateClientAuthentication and GrantResourceOwnerCredentials as per our requirements as shown below to authenticate and authorize user from SharePoint site with User Information list in the SharePoint site.
  8. Now build and test the application by calling the GeToken method and passing "UserName" and "Password" parameters. The method will return the bearer token including token and expiry date time. This token can now be used to perform CRUD operations in SharePoint REST APIs.
Wasn’t that simple? Do try this approach and let me know how it goes for you.






Written by Mahesh Nagawade, Sharepoint Expert at Eternus Solutions
Read More »