Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
bin
public/stylesheets Adds native authentication example for nodejs sdk Sep 16, 2016
routes update field type in google auth Apr 2, 2019
views Minor changes to the authentication exampleapp Jan 31, 2018
.gitignore Adds native authentication example for nodejs sdk Sep 16, 2016
app.js Lint JS in all directories but lib Oct 20, 2017
auth.js implement webhooks CRUD Aug 19, 2019
config.js.template Adds native authentication example for nodejs sdk Sep 16, 2016
package.json update packages with vulnerabilities Jul 26, 2019
readme.md

readme.md

Nylas Connect

This tiny Express app is a simple example of how to use Nylas' Native authentication APIs. You can connect both Exchange accounts and Gmail account's in this example.

It shows how to receive a refresh_token from Google before authenticating with Nylas. Then it uses the Nylas Node SDK to connect an email account and load the user's latest email.

While this steps through the Google OAuth flow manually, you can alternatively use Google API SDKs for node and many other languages. Learn more about that here. You can also learn more about Google OAuth here.

Here is an overview of the complete flow when connecting a Google account.

Your App                                    Google
+------+                                    +-----+
|      |  Redirect user to Oauth Login      |     |
|      +----------------------------------> |     |
|      |                                    |     |
|      |      Authorization code            |     |
|      | <--(localhost)-<-------------------+     |
|      |                                    |     |
|      |      Request refresh token         |     |
|      +----------------------------------> |     |
|      |                                    |     |
|      |     Refresh & access token         |     |
|      | <----------------------------------+     |
|      |                                    +-----+
|      |
|      |
|      |                                    Nylas
|      |     Request Authorization code     +-----+
|      +----------------------------------> |     |
|      |                                    |     |
|      |      Authorization code            |     |
|      | <----------------------------------+     |
|      |                                    |     |
|      |      Request Access Token          |     |
|      +----------------------------------> |     |
|      |                                    |     |
|      |      Access Token                  |     |
|      | <----------------------------------+     |
+------+                                    +-----+

Getting Started

Dependencies

Google Application

You'll need to have a Nylas developer account, a Google Application (if you'd like to connect Google accounts), and the respective client_id and client_secrets. Learn about how to setup the Google App to correctly work with Nylas here.

After you follow that setup doc, you'll have to configure your google client app to properly redirect to this example app. On the Google developer console, under the credentials tab, click the edit button for the client ID that you created. Add http://localhost:3000/google/oauth2callback as an authorized redirect URI and save this change. Now a user will be redirected back to to this example app after authenticating.

Initial Setup

Add your google and nylas client id's and secrets to a new file config.js. See config.js.template for an example.

Then install dependencies with:

npm install

Running the app

Run the express app.

npm start

Visit http://localhost:3000 in your browser.

Auth a gmail account. After, you will be redirected back to the example application. To show a basic use case for what you can do after authing with Nylas, we added a button to get the authed accounts most recent email!

You can’t perform that action at this time.