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

Luis Valencia picture Luis Valencia · Aug 4, 2012 · Viewed 62.3k times · Source

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??

Answer

Mark S. picture Mark S. · Aug 5, 2012

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.