Skip to content

Commit

Permalink
Twitter and Google Oauth for Web (#808)
Browse files Browse the repository at this point in the history
Co-authored-by: Tarraann <[email protected]>
  • Loading branch information
Tarraann and Tarraann authored Jul 19, 2023
1 parent d11fff5 commit 16af253
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
10 changes: 8 additions & 2 deletions gui/pages/Content/Toolkits/ToolkitWorkspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import styles from './Tool.module.css';
import {setLocalStorageValue, setLocalStorageArray, returnToolkitIcon, convertToTitleCase} from "@/utils/utils";

export default function ToolkitWorkspace({toolkitDetails, internalId}) {
export default function ToolkitWorkspace({env, toolkitDetails, internalId}) {
const [activeTab, setActiveTab] = useState('configuration')
const [showDescription, setShowDescription] = useState(false)
const [apiConfigs, setApiConfigs] = useState([]);
Expand All @@ -25,9 +25,15 @@ export default function ToolkitWorkspace({toolkitDetails, internalId}) {
};

function getGoogleToken(client_data) {
var redirect_uri = "";
if (env == "PROD"){
redirect_uri = 'https://app.superagi.com/api/google/oauth-tokens';
}
else {
redirect_uri = "http://localhost:3000/api/google/oauth-tokens";
}
const client_id = client_data.client_id
const scope = 'https://www.googleapis.com/auth/calendar';
const redirect_uri = 'http://localhost:3000/api/google/oauth-tokens';
window.location.href = `https://accounts.google.com/o/oauth2/v2/auth?client_id=${client_id}&redirect_uri=${redirect_uri}&access_type=offline&response_type=code&scope=${scope}`;
}

Expand Down
2 changes: 1 addition & 1 deletion gui/pages/Dashboard/Content.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export default function Content({env, selectedView, selectedProjectId, organisat
<AgentWorkspace internalId={tab.internalId || index} agentId={tab.id} agentName={tab.name} selectedView={selectedView}
agents={agents} fetchAgents={fetchAgents}/>}
{tab.contentType === 'Toolkits' &&
<ToolkitWorkspace internalId={tab.internalId || index} toolkitDetails={toolkitDetails}/>}
<ToolkitWorkspace env={env} internalId={tab.internalId || index} toolkitDetails={toolkitDetails}/>}
{tab.contentType === 'Settings' && <Settings organisationId={organisationId}/>}
{tab.contentType === 'Marketplace' && <Market env={env} selectedView={selectedView}/>}
{tab.contentType === 'Add_Toolkit' && <AddTool internalId={tab.internalId || index}/>}
Expand Down
8 changes: 7 additions & 1 deletion superagi/controllers/google_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from superagi.models.tool_config import ToolConfig
from superagi.models.toolkit import Toolkit
from superagi.models.oauth_tokens import OauthTokens
from superagi.config.config import get_config

router = APIRouter()

Expand All @@ -26,10 +27,15 @@ async def google_auth_calendar(code: str = Query(...), Authorize: AuthJWT = Depe
client_secret = client_secret.value
token_uri = 'https://oauth2.googleapis.com/token'
scope = 'https://www.googleapis.com/auth/calendar'
env = get_config("ENV", "DEV")
if env == "DEV":
redirect_uri = "http://localhost:3000/api/google/oauth-tokens"
else:
redirect_uri = "https://superagi.com/api/google/oauth-tokens"
params = {
'client_id': client_id,
'client_secret': client_secret,
'redirect_uri': "http://localhost:3000/api/google/oauth-tokens",
'redirect_uri': redirect_uri,
'scope': scope,
'grant_type': 'authorization_code',
'code': code,
Expand Down
2 changes: 0 additions & 2 deletions superagi/controllers/twitter_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

@router.get('/oauth-tokens')
async def twitter_oauth(oauth_token: str = Query(...),oauth_verifier: str = Query(...), Authorize: AuthJWT = Depends()):
print("///////////////////////////")
print(oauth_token)
token_uri = f'https://api.twitter.com/oauth/access_token?oauth_verifier={oauth_verifier}&oauth_token={oauth_token}'
conn = http_client.HTTPSConnection("api.twitter.com")
conn.request("POST", token_uri, "")
Expand Down
8 changes: 7 additions & 1 deletion superagi/helper/twitter_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from sqlalchemy.orm import Session
from superagi.models.toolkit import Toolkit
from superagi.models.oauth_tokens import OauthTokens
from superagi.config.config import get_config

class Creds:

Expand All @@ -29,8 +30,13 @@ def get_request_token(self,api_data):
http_method = 'POST'
base_url = 'https://api.twitter.com/oauth/request_token'

env = get_config("ENV", "DEV")
if env == "DEV":
oauth_callback = "http://localhost:3000/api/twitter/oauth-tokens"
else:
oauth_callback = "https://superagi.com/api/twitter/oauth-tokens"
params = {
'oauth_callback': 'http://localhost:3000/api/twitter/oauth-tokens',
'oauth_callback': oauth_callback,
'oauth_consumer_key': api_key,
'oauth_nonce': self.gen_nonce(),
'oauth_signature_method': 'HMAC-SHA1',
Expand Down

0 comments on commit 16af253

Please sign in to comment.