title: Oauth2 and Access Token in SharePoint App
body: <p>I am creating an intranet on SharePoint - O365 where I can a widget where I need to pull calendar events and display them for a week. Here is a steps walk through:</p>
  
  <p>a. User log in to Intranet
  b. Access token is generated to access Office 365 REST API
  c. Calendar events are fetched and displayed.</p>
  
  <p>Here is my problem:</p>
  
  <p>I thought of 2 options to generate the access token</p>
  
  <p>option a: Create a WCF application which accpets user context and generate the token. This will fetch the results and update a list. My intranet app can read a calendar list and update the widget. This didnt work since I was not able to pass the user context from SP to WCF method so that access token can be generated.</p>
  
  <p>Option b: Use the following code (which I have done as of now) but it display the access token in URL which is not good for the client.</p>
  
  <p>var clientId = '>>sample>>';</p>
  
  <pre><code>var replyUrl    = '&lt;&lt;&gt;&gt;'; 
  var endpointUrl = 'https://outlook.office365.com/api/v1.0/me/events';
  var resource = "https://outlook.office365.com/"; 
  
  var authServer  = 'https://login.windows.net/common/oauth2/authorize?';  
  var responseType = 'token'; 
  
  
  var url = authServer + 
          "response_type=" + encodeURI(responseType) + "&amp;" + 
          "client_id=" + encodeURI(clientId) + "&amp;" + 
          "resource=" + encodeURI(resource) + "&amp;" + 
          "redirect_uri=" + encodeURI(replyUrl); 
  </code></pre>
  
  <p>window.location = url; </p>
  
  <p>So is there any other way to achieve this?? </p>
  
  <p>Ankush</p>