Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,26 +24,6 @@ CLIENT_ID = os.getenv('SALESFORCE_CLIENT_ID', 'your_client_id') # Use environme
|
|
| 24 |
CLIENT_SECRET = os.getenv('SALESFORCE_CLIENT_SECRET', 'your_client_secret') # Use environment variables
|
| 25 |
REDIRECT_URI = os.getenv('SALESFORCE_REDIRECT_URI', 'https://huggingface.co/spaces/Yaswanth56/python_test/oauth/callback')
|
| 26 |
|
| 27 |
-
@app.route('/oauth/callback')
|
| 28 |
-
def oauth_callback():
|
| 29 |
-
auth_code = request.args.get('code') # The code returned from Salesforce
|
| 30 |
-
|
| 31 |
-
if not auth_code:
|
| 32 |
-
return jsonify({"error": "No authorization code provided"}), 400
|
| 33 |
-
|
| 34 |
-
# Your OAuth logic to handle the authorization code
|
| 35 |
-
return jsonify({"success": "OAuth callback is working!"})
|
| 36 |
-
|
| 37 |
-
# Salesforce connection setup
|
| 38 |
-
def get_salesforce_connection():
|
| 39 |
-
# Fetch Salesforce credentials from environment variables
|
| 40 |
-
sf = Salesforce(
|
| 41 |
-
username=os.getenv('SALESFORCE_USERNAME', 'your_username'),
|
| 42 |
-
password=os.getenv('SALESFORCE_PASSWORD', 'your_password'),
|
| 43 |
-
security_token=os.getenv('SALESFORCE_SECURITY_TOKEN', 'your_security_token')
|
| 44 |
-
)
|
| 45 |
-
return sf
|
| 46 |
-
|
| 47 |
# OAuth flow to redirect to Salesforce login
|
| 48 |
@app.route('/login')
|
| 49 |
def login():
|
|
@@ -71,8 +51,8 @@ def oauth_callback():
|
|
| 71 |
|
| 72 |
if token_response.status_code == 200:
|
| 73 |
token_info = token_response.json()
|
| 74 |
-
access_token = token_info['
|
| 75 |
-
instance_url = token_info['
|
| 76 |
|
| 77 |
# Store access token in session for future API requests
|
| 78 |
session['access_token'] = access_token
|
|
@@ -102,5 +82,15 @@ def dashboard():
|
|
| 102 |
else:
|
| 103 |
return jsonify({"error": "Failed to fetch user info from Salesforce"}), 400
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
if __name__ == '__main__':
|
| 106 |
app.run(debug=True, host="0.0.0.0", port=7860) # Make sure it listens on the correct port
|
|
|
|
| 24 |
CLIENT_SECRET = os.getenv('SALESFORCE_CLIENT_SECRET', 'your_client_secret') # Use environment variables
|
| 25 |
REDIRECT_URI = os.getenv('SALESFORCE_REDIRECT_URI', 'https://huggingface.co/spaces/Yaswanth56/python_test/oauth/callback')
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
# OAuth flow to redirect to Salesforce login
|
| 28 |
@app.route('/login')
|
| 29 |
def login():
|
|
|
|
| 51 |
|
| 52 |
if token_response.status_code == 200:
|
| 53 |
token_info = token_response.json()
|
| 54 |
+
access_token = token_info['access_token'] # Correct key to fetch the access token
|
| 55 |
+
instance_url = token_info['instance_url'] # Correct key to fetch the instance URL
|
| 56 |
|
| 57 |
# Store access token in session for future API requests
|
| 58 |
session['access_token'] = access_token
|
|
|
|
| 82 |
else:
|
| 83 |
return jsonify({"error": "Failed to fetch user info from Salesforce"}), 400
|
| 84 |
|
| 85 |
+
# Salesforce connection setup
|
| 86 |
+
def get_salesforce_connection():
|
| 87 |
+
# Fetch Salesforce credentials from environment variables
|
| 88 |
+
sf = Salesforce(
|
| 89 |
+
username=os.getenv('SALESFORCE_USERNAME', 'your_username'),
|
| 90 |
+
password=os.getenv('SALESFORCE_PASSWORD', 'your_password'),
|
| 91 |
+
security_token=os.getenv('SALESFORCE_SECURITY_TOKEN', 'your_security_token')
|
| 92 |
+
)
|
| 93 |
+
return sf
|
| 94 |
+
|
| 95 |
if __name__ == '__main__':
|
| 96 |
app.run(debug=True, host="0.0.0.0", port=7860) # Make sure it listens on the correct port
|