I would like to retrieve list of recent files from a particular document library or site for the logged on user

This is using a content editor on a sharepoint classic site

When i run the code below i get error below

Access to XMLHttpRequest at 'https://login.microsoftonline.com//oauth2/v2.0/token/' from origin 'https://tenant.sharepoint.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Using the code below to get an access token and i get the error above

 var token;  
 $(document).ready(function () {  
 function requestToken() {  
     var clientId = ""
     var clientSecret = ""
     var tenantID = ""
     var uri = "https://login.microsoftonline.com/"+ tenantID + "/oauth2/v2.0/token"
         "async": true,  
         "crossDomain": true,  
         "url": "https://login.microsoftonline.com/tenantName/oauth2/v2.0/token", // Pass your tenant 
         "method": "POST",  
         "headers": {  
             "content-type": "application/x-www-form-urlencoded"  
         "data": {  
             "grant_type": "client_credentials",  
             "client_id ": clientId, //Provide your app id      
             "client_secret": clientSecret, //Provide your secret      
             "scope ": "https://graph.microsoft.com/.default",
             "redirectUri" :  "https://tenantName.sharepoint.com"
         success: function (response) {  
             token = response.access_token;  
         error: function (error) {  

I have setup the app registrations and also added Redirect URIs for SPA and Web

Not sure what else I'm missing. Do i need any other settings in azure?

Thanks in Advance

  • Can anyone advice please? Can i get an access token if the script is in a sharepoint classic page?
    – naijacoder
    Jun 3, 2021 at 7:13

1 Answer 1


You can not fetch the details because of browser security feature. Use msal based authentication . Check for msal browser msal library.

  • 1
    Thats what i did and i finally got it working
    – naijacoder
    Nov 30, 2021 at 2:08

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.