Hi there,
I have requirement to fetch planner details on sharepoint custom pages.As per the azure end points I have created the token but it is not valid one.I dont find any other refrence for clinet side to authenthicate the credentials.
So for I tried
- <!DOCTYPE>
- <html>
- <head>
- <title>Sample For Browser</title>
- <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
- <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
- <script type="text/javascript" src="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.10/js/adal.min.js"></script>
- <script type="text/javascript">
- $(function(){
- console.log('Loading');
- var accessToken = "";
- var space = 20;
- var child = 0;
- var configOptions = {
- clientId: "",
- postLogoutRedirectUri: window.location.origin,
- redirectURI: window.location.href,
-
- }
- window.authContext = new AuthenticationContext(configOptions);
- if(authContext.isCallback(window.location.hash))
- {
- authContext.handleWindowCallback();
- }
- var user = authContext.getCachedUser();
- if(user == null){
- authContext.login();
- }
- else
- {
-
-
- getToken();
- }
- function getToken(){
- authContext.acquireToken("https://graph.microsoft.com",function(error, token){
- console.log("Error =" +error);
- console.log("Token =" +token);
- accessToken = token;
- if(accessToken && accessToken != "")
- {
- getOnedriveUser();
- }
- })
- }
- function getOnedriveUser(URL){
- $.ajax({
- url: URL?URL:"https://graph.microsoft.com/v1.0/me/planner/tasks",
- type: 'GET',
- headers: {
- "Authorization": "Bearer " + accessToken
- },
- async:false,
- success: function(data) {
- console.log(data);
- allData = data.value;
- $.each(allData,function(e,item){
- item.parentReference.path.split('root:')[1].split('/').length == 0?child = 0:child = item.parentReference.path.split('root:')[1].split('/').length;
- $('#oneDriveData tbody').append('<tr><td'+(URL?' style="padding-left:'+space*child+'px"':"")+'>'+
- (item.file?"<i class='fa fa-file'></i>":"<i class='fa fa-folder'></i>")+'</td>'+
- '<td>'+(item.name?item.name:" ")+'</td>'+
- '<td>'+new Date(item.lastModifiedDateTime).format('dd/MM/yyyy')+'</td>'+
- '<td>'+new Date(item.lastModifiedDateTime).format('dd/MM/yyyy')+'</td></tr>');
- if(item.folder)
- {
-
- var url = "https://graph.microsoft.com/v1.0/me/drive/items/"+item.id+"/children";
- getOnedriveUser(url);
- }
- })
- },
- error: function(error)
- {
- alert("Error" + error);
- }
- });
- }
- })
- </script>
- </head>
- <body>
- <div class="container-fluide">
- <h1>OneDrive</h1>
- <table id="oneDriveData" class="table table-striped">
- <thead>
- <tr>
- <th>Folder OR File</th>
- <th>Name</th>
- <th>Created Date</th>
- <th>Modify Date</th>
- </tr>
- </thead>
- <tbody></tbody>
- </table>
- </div>
- </body>
- </html>
Through client id i tried to get mircrosoft planner using Microsoft Graph api. Even though getting acess token But I am getting error on https://graph.microsoft.com/v1.0/me/planner/tasks 403 (Forbidden);
can any on suggest me based on this link I reffered https://github.com/microsoftgraph/msgraph-sdk-javascript/blob/dev/samples/browser/src/index.html.