Table of contents
TOC
Collapse the table of content
Expand the table of content

WebAPIHelper Class

SharePoint Dev Documents|Last Updated: 10/6/2017
|
1 Contributor

This class provides helper methods that can be used to protect WebAPI services and to provide a way to reinstantiate a contextobject in the service call.

Namespace:OfficeDevPnP.Core.WebAPI
Assembly: OfficeDevPnP.Core.dll

Inheritance Hierarchy

System.Object

Syntax

public static class WebAPIHelper

Methods

NameDescription
AddToCache(WebAPIContext)Uses the information regarding the requesting app to obtain an access token and caches that using the cachekey. This method is called from the Register WebAPI service api.
GetClientContext(HttpControllerContext)Creates a ClientContext token for the incoming WebAPI request. This is done by - looking up the servicesToken - extracting the cacheKey - get the AccessToken from cache. If the AccessToken is expired a new one is requested using the refresh token - creation of a ClientContext object based on the AccessToken
HasCacheEntry(HttpControllerContext)Checks if this request has a servicesToken cookie. To be used from inside the WebAPI.
RegisterWebAPIService(HttpContextBase, String, Uri)This method needs to be called from a code behind of the SharePoint app startup page (default.aspx). It registers the calling SharePoint app by calling a specific "Register" api in your WebAPI service. Note: Given that method is async you'll need to add the Async="true" page directive to the page that uses this method.

Extension Methods

NameDescription
RegisterWebAPIService(Page, String, Uri)This method needs to be called from a code behind of the SharePoint app startup page (default.aspx). It registers the calling SharePoint app by calling a specific "Register" api in your WebAPI service. Note: Given that method is async you'll need to add the Async="true" page directive to the page that uses this method.

See also

© 2018 Microsoft