craig-rueda commented on code in PR #20280:
URL: https://github.com/apache/superset/pull/20280#discussion_r1046384624


##########
superset/db_engine_specs/gsheets.py:
##########
@@ -122,6 +145,101 @@ def extra_table_metadata(
 
         return {"metadata": metadata["extra"]}
 
+    @staticmethod
+    def is_oauth2_enabled() -> bool:
+        """
+        Return if OAuth2 is enabled for GSheets.
+        """
+        return (
+            "GSHEETS_OAUTH2_CLIENT_ID" in current_app.config
+            and "GSHEETS_OAUTH2_CLIENT_SECRET" in current_app.config
+        )
+
+    @staticmethod
+    def get_oauth2_authorization_uri(database_id: int) -> str:
+        """
+        Return URI for initial OAuth2 request.
+
+        
https://developers.google.com/identity/protocols/oauth2/web-server#creatingclient
+        """
+        default_redirect_uri = url_for("DatabaseRestApi.oauth2", 
_external=True)
+        redirect_uri = current_app.config.get(
+            "GSHEETS_OAUTH2_REDIRECT_URI",
+            default_redirect_uri,
+        )
+
+        # state to be passed back to Superset after authenticating so it can 
store the
+        # OAuth2 token
+        payload: OAuth2State = {
+            "database_id": database_id,
+            "user_id": g.user.id,
+            # if the config has a custom redirect URI (eg, because Superset is 
behind a
+            # proxy) we need the original redirect URI so that the request can 
be
+            # forwarded
+            "default_redirect_uri": default_redirect_uri,
+        }
+
+        # sign payload to prevent spoofing
+        state = jwt.encode(
+            payload=payload,
+            key=current_app.config["SECRET_KEY"],
+            algorithm="HS256",

Review Comment:
   do we want the algo to be configurable?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to