All docs This doc
Skip to end of metadata
Go to start of metadata

Get User Credentials

Create an office365 account using URL https://login.microsoftonline.com/ , and go to SharePoint.

Note

This is a 30-day free trial account.

Follow the below mentioned steps to generate the access token

  1. Log in to your Office365 account, and go to the URL: https://your_site_name.sharepoint.com/_layouts/15/appregnew.aspx

  2. Set the following options:

    • App Type - Select An app running on a web server. (You may not have this option)
    • Client Id - Click Generate, and copy the generated value to a text file.
    • Client Secret - Click Generate, and copy the generated value to a text file.
    • Title - Enter a name for the app.
    • App Domain - Enter the domain name.
    • Redirect URL -  Enter the Callback URL.
  3. Click Create. Now you can configure the newly created app to access SharePoint resources.
  4. Go to Site settings > Site app permissions. The realm ID is displayed under App Identifier to the right of the @ sign. It will display with the format
    i:0i.t|ms.sp.ext|<audience principal ID>@<site_realm>
    Get the Realm of your site. Realm is a constant GUID for a site. Save this realm for future use.
  5. Get the Authorization code from Azure Access Control Service Construct the authorization url as: https://your_site.sharepoint.com/_layouts/15/OAuthAuthorize.aspx?client_id=client_GUID&scope=app_permissions_list&response_type=code&redirect_uri=redirect_uri
    Set the scope=Web.Manage
  6. Once you grant the permission (by clicking trust), SharePoint Online site asks ACS to create an authorization code unique to this combination of user and app. ACS sends the authorization code to the SharePoint site. SharePoint Online site redirects the browser back to the redirect URI that was specified when the app was registered in step 1 and 2. It also includes the authorization code as a query string. The redirect URL is structured as: https://redirect_url/?code=<authcode>
    Extract query string value code from above url and it will be used in next step.
  7. Get the access token and refresh token from code:
    Construct the below post request:

    URL: https://accounts.accesscontrol.windows.net//tokens/OAuth/2
    Post parameters:
    grant_type=authorization_code
    &client_id=<client_id>@<site_realm>
    &client_secret=<client_secret
    &code=<auth_code>
    &redirect_uri=<redirect_url>
    &resource=<audience principal ID>/<site_host>@<site_realm>

    The example for the site_host: your_site_name.sharepoint.com

  8. Get the access token from refresh token:
    This step is almost similar to step 7, except 2 differences. Here the difference is that we use:

    • grant_type as refresh_token and
    • refresh_token instead of code in step 7 and use the refresh token which we have saved in step 7.

    URL: https://accounts.accesscontrol.windows.net/<site_realm>/tokens/OAuth/2

Initializing the Connector

To use the SharePoint connector, add the <sharepoint.init> element in your configuration before any other SharePoint operations. This configuration authenticates with SharePoint by configuring the user credentials using OAuth2 authentication for accessing the Microsoft office365 account that contains the sharepoint. For more information on authorizing requests in SharePoint.

init
<sharepoint.init>
 	<apiUrl>{$ctx:apiUrl}</apiUrl>
 	<accessToken>{$ctx:accessToken}</accessToken>
 	<id>{$ctx:id}</id>
 	<clientId>{$ctx:clientId}</clientId>
 	<clientSecret>{$ctx:clientSecret}</clientSecret>
 	<refreshToken>{$ctx:refreshToken}</refreshToken>
 	<redirectUri>{$ctx:redirectUri}</redirectUri>
 	<resource>{$ctx:resource}</resource>
 	<registryPath>{$ctx:registryPath}</registryPath>
 	<intervalTime>{$ctx:intervalTime}</intervalTime>
    <blocking>{$ctx:blocking}</blocking>
 </sharepoint.init>
Properties 
  • accessToken: OAuth Token to read and manipulate data of Sharepoint API.
  • apiUrl: Base endpoint URL of Sharepoint API.
  • id:  Realm id, This is a constant GUID for a site.
  • registryPath: Registry Path of the Connector where the values are stored.  
  • intervalTime: Accesstoken expiration time interval.
  • clientId: The value of your API Key given when you registered your application with Sharepoint and append realm id with client id with this formate <client_id>@<realm_id>.

  • clientSecret: The value of your secret key given when you registered your application with Sharepoint.

  • refreshToken: RefreshToken to be used to obtain the access token.

  • id:  Realm id, This is a constant GUID for a site.
  • redirectUrl:  The redirect url, that you passed to get code.
  • resource: The App ID URI of the web API.

  • blocking: The blocking parameter is helping connector performs the blocking invocations to Sharepoint.

To get the OAuth access token add  <sharepoint.getAccessTokenFromRefreshToken> element before <sharepoint.init> element in your configuration.

getAccessTokenFromRefreshToken
<sharepoint.getAccessTokenFromRefreshToken>
 	<id>{$ctx:id}</id>
 	<clientId>{$ctx:clientId}</clientId>
 	<clientSecret>{$ctx:clientSecret}</clientSecret>
 	<refreshToken>{$ctx:refreshToken}</refreshToken>
 	<redirectUri>{$ctx:redirectUri}</redirectUri>
 	<resource>{$ctx:resource}</resource>
 </sharepoint.getAccessTokenFromRefreshToken>
properties
  • clientId: The value of your API Key given when you registered your application with Sharepoint and append realm id with client id with this formate <client_id>@<realm_id>.

  • clientSecret: The value of your secret key given when you registered your application with sharepoint.

  • refreshToken: RefreshToken to be used to obtain the access token.

  • id:  Realm id, This is a constant GUID for a site.
  • redirectUrl:  The redirect url, that you passed to get code.
  • resourceThe App ID URI of the web API.
  • blockingThe blocking parameter is helping connector performs the blocking invocations to Sharepoint.

Additional information

Ensure that the following Axis2 configurations are added and enabled.

Required message formatters
messageFormatters
<messageFormatter contentType="application/json;odata=verbose" class="org.apache.synapse.commons.json.JsonFormatter"/>
<messageFormatter contentType="application/octet-stream" class="org.apache.axis2.format.BinaryFormatter"/>
Required message builders
messageBuilders
<messageBuilder contentType="application/json;odata=verbose" class="org.apache.synapse.commons.json.JsonBuilder"/>
<messageBuilder contentType="binary/octet-stream" class="org.wso2.carbon.relay.BinaryRelayBuilder"/>


Ensure that
before you call connector methods with blocking mode, the following builders and formatter are added and enabled in axis2_blocking_client.xml.

Required message formatters
messageFormatters
<messageFormatter contentType="application/json;odata=verbose" class="org.apache.synapse.commons.json.JsonStreamFormatter"/>
<messageFormatter contentType="application/octet-stream" class="org.apache.axis2.format.BinaryFormatter"/>
Required message builders
messageBuilders
<messageBuilder contentType="application/json;odata=verbose" class="org.apache.synapse.commons.json.JsonStreamBuilder"/>
<messageBuilder contentType="binary/octet-stream" class="org.wso2.carbon.relay.BinaryRelayBuilder"/>

Now that you have connected to SharePoint, use the information in the following topics to perform various operations with the connector.


  • No labels