Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #48 from xingren23/dev
Browse files Browse the repository at this point in the history
deploy on autodl
  • Loading branch information
xingren23 authored Dec 20, 2023
2 parents c171360 + dcea7f1 commit 3f36e30
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .streamlit/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ baseUrlPath = ""
# `server.enableXsrfProtection`.

# Default: true
enableCORS = true
enableCORS = false

# Enables support for Cross-Site Request Forgery (XSRF) protection, for added
# security.
Expand All @@ -78,7 +78,7 @@ enableCORS = true
# `server.enableXsrfProtection`.

# Default: true
enableXsrfProtection = true
enableXsrfProtection = false

# Max size, in megabytes, for files uploaded with the file_uploader.

Expand Down
32 changes: 22 additions & 10 deletions modules/discord_oauth.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,45 @@
import os
from loguru import logger
import discordoauth2

import streamlit as st

client_id = os.getenv('DISCORD_CLIENT_ID')
client_secret = os.getenv('DISCORD_CLIENT_SECRET')
redirect_uri = os.getenv('DISCORD_REDIRECT_URI')

client = discordoauth2.Client(client_id, secret=client_secret, redirect=redirect_uri)

@st.cache_resource
def get_client():
return client
try:
import discordoauth2
client = discordoauth2.Client(client_id, secret=client_secret, redirect=redirect_uri)
return client
except Exception as e:
logger.error(f"get_client error: {e}")
return None


@st.cache_data(ttl=60 * 60)
def gen_authorization_url():
client = get_client()
authorization_url = client.generate_uri(scope=["identify", "email"])
logger.debug(f"authorization_url: {authorization_url}")
return authorization_url
if client:
authorization_url = client.generate_uri(scope=["identify", "email"])
logger.debug(f"authorization_url: {authorization_url}")
return authorization_url
else:
authorization_url = f"https://discord.com/oauth2/authorize?client_id={client_id}&scope=identify+email&redirect_uri={redirect_uri}&response_type=code"
logger.warning(f"discordoauth2 is none, default authorization_url : {authorization_url}")
return authorization_url


def get_user_data(code):
try:
client = get_client()
access = client.exchange_code(code)
user_data = access.fetch_identify()
logger.debug(f"user_data: {user_data}")
return user_data
if client:
access = client.exchange_code(code)
user_data = access.fetch_identify()
logger.debug(f"user_data: {user_data}")
return user_data
except Exception as e:
logger.error(f"get_user_data error: {e}")
return None
Expand Down

0 comments on commit 3f36e30

Please sign in to comment.