diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f6f8d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules +.env +package-lock.json + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..36fca7a --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,133 @@ + +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +[INSERT CONTACT METHOD]. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available +at [https://www.contributor-covenant.org/translations][translations]. + +[homepage]: https://www.contributor-covenant.org +[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..821ed35 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1 @@ +Use of this sample app is subject to our [Terms of Use](https://zoom.us/docs/en-us/zoom_api_license_and_tou.html) \ No newline at end of file diff --git a/README.md b/README.md index 66b4806..2ad7a7f 100644 --- a/README.md +++ b/README.md @@ -1 +1,132 @@ -# zoom-jwt +# Zoom OAuth Hello World + +Use of this sample app is subject to our [Terms of Use](https://zoom.us/docs/en-us/zoom_api_license_and_tou.html) + +This is a Hello World app using an OAuth Marketplace App client ID and Secret to create an OAuth token, used to call the Zoom API. + +Follow along with relevant Zoom OAuth documentation as we set this up: + +1. [OAuth with Zoom](https://marketplace.zoom.us/docs/guides/authorization/oauth/oauth-with-zoom) +2. [Create an OAuth App](https://marketplace.zoom.us/docs/guides/getting-started/app-types/create-oauth-app) + +## Setup app locally + +Clone and install the app and it's dependencies. We'll be using [Express](https://www.npmjs.com/package/express) for a basic Node.js server, [dotenv](https://www.npmjs.com/package/dotenv) for our credentials, [requests](https://www.npmjs.com/package/requests) to make HTTP requests and [nodemon](https://www.npmjs.com/package/nodemon) for easier development refreshing. + +```bash +git clone https://github.com/zoom/zoom-oauth-sample-app.git +``` + +```bash +cd zoom-oauth-sample-app && npm install +``` + +Run server: + +```bash +npm run start +``` + +### Setup dotenv +Create a `.env` file in which to store your PORT, access credentials, and Redirect URL. + +```bash +touch .env +``` + +Copy the following into this file, which we'll add your own values to: + +``` +clientID= +clientSecret= +redirectURL= +``` + +> Remember: Never share or store your client credentials publicly. Your `.env` is included in the `.gitignore` file to ensure these files won't be included in a git workflow. + +## Install [ngrok](https://ngrok.com/) + +During the OAuth flow, Zoom will need to know where to redirect a user after they have successfully authenticated and installed the app on their account. + +For this we'll use [ngrok](https://ngrok.com/download), which creates a public link to a localhost development server. + +Download and install ngrok, then follow the steps to connect your account. + +Run ngrok on the same localhost port (4000): + +```bash +~/./ngrok http 4000 +``` + +This will generate a forwarding link. Copy this and add it into your `.env` file as the `redirectURL`. Keep ngrok running! If the linkage disconnects, we'll need to read a new redirectURL. + +Example: + +``` +redirectURL=https://12345678.ngrok.io +``` + + +## Create an OAuth App on the Zoom App Marketplace + +Sign in to the Zoom App Marketplace and [Create an OAuth App](https://marketplace.zoom.us/develop/create?source=devdocs). + +Creating this app will generate your OAuth Client ID and Secret needed to install on your account and get an access token. + +Copy these credentials and add them to your `.env` file. + +Example: + +``` +clientID=1234567890 +clientSecret=13245678901234567890 +redirectURL=https://12345678.ngrok.io +``` + +### Add your Redirect URL from ngrok to your app + +Copy and paste your ngrok link into the Redirect URL for OAuth field, then click Continue. + +### Fill out app information. + +To install the app, we'll need to add some quick info on the app. Add in the following: + +1. *Short Description* +2. *Long Description* +3. *Developer Name* +4. *Developer Contact* + + +> We won't need to add any Features to our app, but if we wanted to enable [Event Subscriptions](https://marketplace.zoom.us/docs/guides/tools-resources/webhooks#event-subscriptions) through Zoom Webhooks, we'd do it here. + +### Add Scopes + +OAuth is used to guarantee that an app only has access to the data you authorize. If an app does not have the required scope, it cannot call the API on your behalf. + +To request data,we'll need to add a Scope to our app. The only data we need is for a user's profile information. Click **+ Add Scopes** and add *"View your user information"* (`user:read`). Click **Done** and continue on to the Installation page. + +## Install app + +With our app running on `localhost:4000`, a live redirectURL from ngrok, and proper scopes requested we can now install the app on our account. + +Click **Install** or copy the Installation URL into a browser. + +Zoom will now ask you to authorize the app on your account. Note that the app is requesting only the scope we've added. + +> If you're not the admin on your Zoom account, the admin might require you to ask them for pre-approval to install this app. Submit a request to get this pre-approved by your account admin. + +Authorizing the app will send you to the Redirect URL of your app, linked to our app running on localhost:4000. + +Your express server will log your access_token, refresh_token and the API call response to get your user information. + +In your browser, you'll see your Zoom profile data, with a JSON object showing the response. This API request was made using an `access_token` specific to this app and scopes. + +## Next steps + +Follow our documentation on OAuth with Zoom for more information on building a user-level app on the Zoom App Marketplace. + +Code happy! + +## Need help? + +If you're looking for help, try [Developer Support](https://devsupport.zoom.us) or our [Developer Forum](https://devforum.zoom.us). Priority support is also available with [Premier Developer Support](https://zoom.us/docs/en-us/developer-support-plans.html) plans. diff --git a/index.js b/index.js new file mode 100644 index 0000000..5fb452a --- /dev/null +++ b/index.js @@ -0,0 +1,93 @@ +// Bring in environment secrets through dotenv +require('dotenv/config') + +// Use the request module to make HTTP requests from Node +const request = require('request') + +// Run the express app +const express = require('express') +const app = express() + + +app.get('/', (req, res) => { + + // Step 1: + // Check if the code parameter is in the url + // if an authorization code is available, the user has most likely been redirected from Zoom OAuth + // if not, the user needs to be redirected to Zoom OAuth to authorize + + if (req.query.code) { + + // Step 3: + // Request an access token using the auth code + + let url = 'https://zoom.us/oauth/token?grant_type=authorization_code&code=' + req.query.code + '&redirect_uri=' + process.env.redirectURL; + + request.post(url, (error, response, body) => { + + // Parse response to JSON + body = JSON.parse(body); + + // Logs your access and refresh tokens in the browser + console.log(`access_token: ${body.access_token}`); + console.log(`refresh_token: ${body.refresh_token}`); + + if (body.access_token) { + + // Step 4: + // We can now use the access token to authenticate API calls + + // Send a request to get your user information using the /me context + // The `/me` context restricts an API call to the user the token belongs to + // This helps make calls to user-specific endpoints instead of storing the userID + + request.get('https://api.zoom.us/v2/users/me', (error, response, body) => { + if (error) { + console.log('API Response Error: ', error) + } else { + body = JSON.parse(body); + // Display response in console + console.log('API call ', body); + // Display response in browser + var JSONResponse = '
' + JSON.stringify(body, null, 2) + ''
+ res.send(`
+
+ ${body.role_name}, ${body.company}
+