How can I get an oauth access token in sharepoint 2013?

65,679

Solution 1

Your entire approach is incorrect. When it comes to accessing the REST services of a sharepoint 2013 server using javascript you don't need an Access Token. You have to use the Sharepoint 2013 cross-domain library instead.

The page at http://msdn.microsoft.com/en-us/library/jj164022.aspx explains after showing a classic REST request using an oauth token:

This request would look a little different if you are writing your app in JavaScript but using the SharePoint 2013 cross-domain library. In this case, you don’t need to provide an access token. The following code demonstrates how this request would look if you are using the cross-domain library and want to receive the OData representation of the lists as XML instead of JSON. See How to: Access SharePoint 2013 data from remote apps using the cross-domain library for more information about using the cross-domain library.

This is currently the url to that article http://msdn.microsoft.com/en-us/library/fp179927.aspx

This should be your correct answer

Solution 2

There doesn't seem to be a way to get the access token only using JavaScript. You need to use an app to generate the access token. See the Sharepoint OAuth Tips and FAQs for more information about how to get the token.

Share:
65,679

Related videos on Youtube

Luis Valencia
Author by

Luis Valencia

Updated on July 09, 2022

Comments

  • Luis Valencia
    Luis Valencia almost 2 years

    I have this site here: http://msdn.microsoft.com/en-us/library/jj164022(v=office.15).aspx

    the text in some part says: The following JavaScript code demonstrates how to make this GET request that returns a JSON representation of all of a site’s lists by using JQuery. It also assumes that you have a valid OAuth access token that is stored in the accessToken variable. You do not need the access token if you make this call from inside an app web, as you would in a SharePoint-hosted app.

    jQuery.ajax({
    url: http:// site url/_api/web/lists,
    type: "GET",
    headers: {
    "ACCEPT","application/json;odata=verbose",
    "Authorization", "Bearer " + accessToken
    },
    })
    

    the specific question is how can I get the access token??

  • AnimaSola
    AnimaSola almost 10 years
    How do you generate a token for apps/services accessing SharePoint lists via REST?
  • Radu Simionescu
    Radu Simionescu almost 10 years
    @AnimaSola I don't know that... I searched for that answer myself a lot. Oauth seems to be used only for Sharepoint Apps. What I did end up doing was to authenticate the rest calls using the sharepoint clasic flow: present a webview to the sharepoint page indicated by user, grab the FedAuth and rTfa cookies after user authenticates with Microsoft, and attach them with every rest call
  • Altaf Patel
    Altaf Patel almost 9 years
    In that case how we can access REST API in client like Android or iOS devices ?
  • Clarence
    Clarence over 4 years
    This seems to contradict Sharepoint code examples where it uses an access token. If an approach exists within the documentation that uses Autho then how does that make using Autho incorrect. For my purpose the Sharepoint cross domain library doesn't work. I need to use Autho. So if anyone has that infornmation it owuld be great for me