Skip to content

A proxy server of Node.js which allows you to use evernote-sdk-js on a pure client side application

License

Notifications You must be signed in to change notification settings

kokufu/evernote-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Evernote OAuth Proxy

For security reasons, Evernote javascript api does not normally work on any browsers.
This application works as a proxy server and allows you to use evernote-sdk-js on a pure client side application.

REF
Does the API support CORS (Cross origin resource sharing)

Setup

  1. Get Evernote API Consumer Key and Consumer Secret from here.

  2. Copy config.json.template to config.json and fill in your values.

  3. Install dependencies.

    $ npm install
    

Usage

  1. Start server

    $ node server.js
    
  2. Access to http:https://localhost:9999/oauth?callbackurl=http:https://xxx.html
    Change http:https://localhost:9999 and callbackurl value http:https://xxx.html according to your environment.

  3. You will be redirected to Evernote authentication page.

  4. When authentication is successful, you will be redirected to http:https://xxx.html with the query param oauthAccessToken.

    NOTE The oauthAccessToken is encoded, so you have to decode it by decodeURIComponent function.

  5. You can use oauthAccessToken for evernote-sdk-js by using http:https://localhost:9999/noteStore?oauthAccessToken=yyy as noteStoreURL.

  6. See also Sample client and REDME.md of "Evernote SDK for JavaScript".
    You can see all functions of NoteStore here.

Sample client

Below is a simple application to get the oauthAccessToken and to show notebook list.

Before using it, download evernote-sdk-minified.js and store it at js/ directory.
evernote-sdk-minified.js can be downloaded from production directory of evernote-sdk-js.

<!DOCTYPE html>
<html>
<head>
<script src="js/evernote-sdk-minified.js"></script>
<script type="text/javascript">
  function getParameter(name) {
    var regex = new RegExp(name + "=(.+?)(&|$)");
    try {
      return decodeURIComponent(regex.exec(location.search)[1]);
    } catch (e) {
      return undefined;
    }
  }

  // TODO change to valid server
  var proxyServerAddr = "http:https://localhost:9999";

  var oauthAccessToken = getParameter("oauthAccessToken");
  if (!oauthAccessToken) {
    var selfAddr = window.location.href.replace(/window.location.search/, "");
    // redirect to auth page
    window.location.href = proxyServerAddr + "/oauth" + "?callbackurl=" + selfAddr;
  } else {
    var noteStoreURL = proxyServerAddr + "/noteStore" + "?oauthAccessToken=" + oauthAccessToken;
    var noteStoreTransport = new Thrift.BinaryHttpTransport(noteStoreURL);
    var noteStoreProtocol = new Thrift.BinaryProtocol(noteStoreTransport);
    var noteStore = new NoteStoreClient(noteStoreProtocol);
    // Get the notebook list and display on console.
    noteStore.listNotebooks(oauthAccessToken,
      function(notebooks) {
        console.log(notebooks);
      },
      function (error) {
        console.log(error.errorCode + ": " + error.parameter);
      });
  }
</script>
</head>
</html>

Deploy on Heroku

  1. Create a new Heroku app

    heroku apps:create APP_NAME
    
  2. Provide API_CONSUMER_KEY and API_CONSUMER_SECRET:

    heroku config:set API_CONSUMER_KEY=XXXX API_CONSUMER_SECRET=YYYY
    
  3. Push changes to heroku

    git push heroku master
    

OR

heroku restart

Acknowledgment

I decided to make this app for StackEdit and consulted Gatekeeper.

About

A proxy server of Node.js which allows you to use evernote-sdk-js on a pure client side application

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published