I am trying to authenticate to Sharepoint 2013 from a Dynamics CRM 2013 plugin, all within a single Office 365 environment. I am ultimately trying to copy an email attachment from Dynamics CRM to Sharepoint (Post Email Attachment Create Async). So far this journey has been fraught with obstacles.

  • I have gone to AppRegNew.aspx to get a client id and secret.
  • I have built a web request and posted the information to mycompanyname.sharepoint.com/_layouts/15/OAuthAuthorize.aspx but receive a 403 Forbidden error.
  • I can't use CSOM because I am unable to deploy the Sharepoint.Client.dll to the Dynamics CRM Online
  • I'm not sure what the scope in the request paramaters should be

Here is a code excerpt from what I have so far :

string clientId = "myclientid";
string clientSecret = "asecretstring";

this.request = string.Format("grant_type=client_credentials&client_id={0}&client_secret={1}&scope=list.read", Uri.EscapeDataString(clientId), Uri.EscapeDataString(clientSecret));

WebRequest webRequest = WebRequest.Create(OAuthUri);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
byte[] bytes = Encoding.ASCII.GetBytes(this.request);
webRequest.ContentLength = bytes.Length;
using (Stream outputStream = webRequest.GetRequestStream())
    outputStream.Write(bytes, 0, bytes.Length);

// This is where I get a 403
using (WebResponse webResponse = webRequest.GetResponse())
    // get token from the response

I would really appreciate some direction in authenticating between the two Office 365 systems.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.