singer-io / tap-zoom

GNU Affero General Public License v3.0
4 stars 16 forks source link

List of Necessary OAuth Granular Scopes #30

Open GroovyDan opened 2 months ago

GroovyDan commented 2 months ago

Zoom recently release OAuth Granular Scopes to replace Classic Scopes (see: https://developers.zoom.us/docs/integrations/oauth-scopes-overview/). Does anyone have a list of the necessary granular scopes that need to be added to the OAuth app for this integration to pull data via the API? It appear you can no longer use the listed classic scopes.

GroovyDan commented 2 months ago

Got it working. Here are the granular scopes I added: image image (1)

AndrewLWilson commented 1 month ago

@GroovyDan I'm trying to get this working with granular scopes using Stitch. Did you create a server-to-server Zoom app or a normal one? I created a server-to-server Zoom app but realized it does not use a refresh token.

GroovyDan commented 1 month ago

@AndrewLWilson I created a normal one. Getting the initial refresh token can also be a pain. Here's some code that you can use to get one once you have the app set up:

"""
usage: get_refresh_token.py [-h] --client-id CLIENT_ID --client-secret CLIENT_SECRET --authorization-code AUTHORIZATION_CODE --redirect-uri REDIRECT_URI

Example:

$ poetry run python3 get_refresh_token.py \
    --client-id '[CLIENT-ID]' \
    --client-secret '[CLIENT-SECRET]' \
    --authorization-code '[AUTH-CODE]' \
    --redirect-uri [your-redirect-uri]
"""

import argparse
import json
from base64 import b64encode

import requests

def get_zoom_oauth_tokens(
    client_id: str, client_secret: str, code: str, oauth_redirect_uri: str
) -> dict:
    """
    Reference: https://developers.zoom.us/docs/integrations/oauth/#step-2-request-access-token
    """
    base64_auth_string = b64encode(
        f"{client_id}:{client_secret}".encode("ascii")
    ).decode("ascii")

    post_data = {
        "code": code,
        "grant_type": "authorization_code",
        "redirect_uri": oauth_redirect_uri,
    }

    headers = {
        "Authorization": f"Basic {base64_auth_string}",
        "Content-Type": "application/x-www-form-urlencoded",
    }

    print("\n\nFetching OAuth Tokens from https://zoom.us/oauth/token")
    response = requests.post(
        "https://zoom.us/oauth/token",
        data=post_data,
        headers=headers,
    )
    oauth_json = response.json()

    print(f"Response: {json.dumps(oauth_json, indent=2)}")

    return oauth_json

def main(
    client_id: str,
    client_secret: str,
    authorization_code: str,
    redirect_uri: str,
) -> None:
    oauth = get_zoom_oauth_tokens(
        client_id=client_id,
        client_secret=client_secret,
        code=authorization_code,
        oauth_redirect_uri=redirect_uri,
    )
    access_token, refresh_token = oauth["access_token"], oauth["refresh_token"]

    print(f"ACCESS TOKEN = {access_token}")
    print(f"REFRESH TOKEN = {refresh_token}")

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--client-id", type=str, required=True)
    parser.add_argument("--client-secret", type=str, required=True)
    parser.add_argument("--authorization-code", type=str, required=True)
    parser.add_argument("--redirect-uri", type=str, required=True)
    args = parser.parse_args()

    main(
        client_id=args.client_id,
        client_secret=args.client_secret,
        authorization_code=args.authorization_code,
        redirect_uri=args.redirect_uri,
    )
AndrewLWilson commented 1 month ago

@GroovyDan wow, thank you so much for all of this! I'll try this out and let you know how it goes. Thanks you so much for your generosity, I owe you one!

AndrewLWilson commented 1 month ago

Success! I didn't know how to obtain the authorization_code for your script, but I was able to follow the readme of this and that logged the refresh token that Stitch requires. Thank you thank you thank you!