I'm using Office 365 SharePoint and I need to be able to upload a file to a specific SharePoint document list from a website running on a non SharePoint server. I've read dozens and dozens of theoretical posts about this, but none of them give concrete examples of how it is actually done from start to finish.

I may be heading in the wrong direction here, but so far I have registered an app on my SharePoint site at this URL https://www.MySharePointSite/_layouts/15/appregnew.aspx and I have a client_id and client_secret for the app. Using these 2 id's, I retrieved some sort of code from here https://www.MySharePointSite/_layouts/15/OAuthAuthorize.aspx?client_id={client_id}&scope=Web.Write&response_type=code}. Now it looks like the next step is to use this code to get an access token that is needed to make REST calls to access my SharePoint documents, which leads me to my question. What is the URL to get this access token? I've seen several different partially-formed URLs to get an access token, none of which I can figure out.

I am not using C# or Visual Studio for any of this, so the C# libraries to do all of this will be of no use to me, I just need the URL and parameters needed to retrieve an access token. Any info at all will be much appreciated.

2 Answers 2



You are in the right direction.

LONG ANSWER (I basically copied some of the items in the blog link I referred you to before. So credits to the blog owner, Jomit Vaghela, on the blog post with title "Authentication and Authorization with remote apps in Office 365 and SharePoint Online (Part 1)"):

After getting that code, next step is get the realm GUID. To do that, issue a GET request to "https:///_vti_bin/client.svc" with the Authorization header equal to "Bearer".

Sample pseudocode: request.URI = "https:///_vti_bin/client.svc"; request.Method = HTTP_GET; request.Header["Authorization"] = "Bearer";

From the response in this GET request, you will have to parse for the Header named "WWW-Authenticate":

realmGUID = response.m_respHeader["WWW-Authenticate"].substr(14, 36);

Note: This realm GUID parsing is directly taken from their TokenHelper class.

Finally, you can get the access token by issuing a POST request like this:

request.URI = "https://accounts.accesscontrol.windows.net/" + realmGUID + "/tokens/OAuth/2";
request.Method = HTTP_POST;
request.m_form["grant_type"] = "authorization_code";
request.m_form["client_id"] = <Client ID>+ "@" + realmGUID;
request.m_form["client_secret"] = <Client Secret>;
request.m_form["code"] = <Code you got from OAuthAuthorize.aspx>;
request.m_form["redirect_uri"] = <Redirect URL>;
request.m_form["resource"] = <Target Principal Name> + "/"+ <sharepoint_site> + "@" + realmGUID;

Note: Typically, if you are accessing SharePoint, is equal to "00000003-0000-0ff1-ce00-000000000000".For a complete list, please refer to http://blogs.msdn.com/b/kaevans/archive/2013/04/05/inside-sharepoint-2013-oauth-context-tokens.aspx

Oops. You don't like list. So I'll enumerate again -

  • ACS: 00000001-0000-0000-c000-000000000000
  • Exchange: 0000002-0000-0ff1-ce00-000000000000
  • SharePoint: 00000003-0000-0ff1-ce00-000000000000
  • Lync: 00000004-0000-0ff1-ce00-000000000000
  • Workflow: 00000005-0000-0000-c000-000000000000

The response from the POST request will contain your access token.

If I still did not satisfy the standards of answering questions here in sharepoint.stackexchange, just delete this immediately.

  • 2
    Please update your answer with a summary of the solution in the link you reference. Link only answers have limited usefulness, as links tend to break over time.
    – Phil Greer
    Commented Sep 24, 2014 at 1:48
  • updated the answer
    – Passerby
    Commented Nov 18, 2014 at 0:05

Refer this url for complete steps to achieve OAuth to a SharePoint Online Site.


All the steps are explained in a simple way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.