Yaswanth56 commited on
Commit
7aa2f67
·
verified ·
1 Parent(s): 9b43c0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -14
app.py CHANGED
@@ -1,24 +1,38 @@
1
  from flask import Flask, render_template, request, jsonify, redirect, url_for, session
2
  from flask_session import Session # Import the Session class
3
  from flask.sessions import SecureCookieSessionInterface # Import the class
4
- from salesforce import get_salesforce_connection
5
  from flask_cors import CORS
6
  import os
7
-
8
- from flask import Flask, redirect, request, jsonify, session
9
  import requests
10
- import os
11
 
 
12
  app = Flask(__name__)
13
  app.secret_key = os.urandom(24) # Random secret key for session management
14
 
15
- # Salesforce OAuth URLs and credentials
 
 
 
 
 
 
 
16
  SALESFORCE_OAUTH_URL = "https://login.salesforce.com/services/oauth2/authorize"
17
  SALESFORCE_TOKEN_URL = "https://login.salesforce.com/services/oauth2/token"
18
- CLIENT_ID = '3MVG9WVXk15qiz1JbtW1tT9a7WojFUbAfMVyVXfvI4PISHAKAxmZ8RLS1lBHqpnaDPQPZOOInuVdcQpi7smWc' # Your Consumer Key
19
- CLIENT_SECRET = '36C463CD713C420BA2ED78F853359EACCE1ECCE2954C9810FFD7F946564CB0E8' # Your Consumer Secret
20
- REDIRECT_URI = 'https://huggingface.co/spaces/nagasurendra/BiryaniHubflask21' # Your Hugging Face redirect URI
21
- INSTANCE_URL = 'https://biryanihub-dev-ed.develop.my.site.com/s/welcomePage' # Your Salesforce instance URL
 
 
 
 
 
 
 
 
 
22
 
23
  # OAuth flow to redirect to Salesforce login
24
  @app.route('/login')
@@ -47,8 +61,8 @@ def oauth_callback():
47
 
48
  if token_response.status_code == 200:
49
  token_info = token_response.json()
50
- access_token = token_info['sSSjyhInIsUohKpG8sHzty2q']
51
- instance_url = token_info['https://biryanihub-dev-ed.develop.my.site.com/s/welcomePage'] # The Salesforce instance URL
52
 
53
  # Store access token in session for future API requests
54
  session['access_token'] = access_token
@@ -78,7 +92,5 @@ def dashboard():
78
  else:
79
  return jsonify({"error": "Failed to fetch user info from Salesforce"}), 400
80
 
81
-
82
  if __name__ == '__main__':
83
- app.run(debug=True)
84
-
 
1
  from flask import Flask, render_template, request, jsonify, redirect, url_for, session
2
  from flask_session import Session # Import the Session class
3
  from flask.sessions import SecureCookieSessionInterface # Import the class
4
+ from simple_salesforce import Salesforce
5
  from flask_cors import CORS
6
  import os
 
 
7
  import requests
 
8
 
9
+ # Initialize Flask app
10
  app = Flask(__name__)
11
  app.secret_key = os.urandom(24) # Random secret key for session management
12
 
13
+ # Configure session management
14
+ app.config["SESSION_COOKIE_SECURE"] = False # Temporarily disable secure cookie
15
+ app.config["SESSION_COOKIE_SAMESITE"] = "Lax" # Use "Lax" instead of "None"
16
+ app.config["SESSION_TYPE"] = "filesystem" # Use filesystem for session storage
17
+ Session(app) # Initialize the session interface
18
+ CORS(app) # Enable Cross-Origin Resource Sharing (CORS)
19
+
20
+ # Salesforce OAuth URLs and credentials from environment variables for security
21
  SALESFORCE_OAUTH_URL = "https://login.salesforce.com/services/oauth2/authorize"
22
  SALESFORCE_TOKEN_URL = "https://login.salesforce.com/services/oauth2/token"
23
+ CLIENT_ID = os.getenv('SALESFORCE_CLIENT_ID', 'your_client_id') # Use environment variables
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/nagasurendra/BiryaniHubflask21') # Your Hugging Face redirect URI
26
+
27
+ # Salesforce connection setup
28
+ def get_salesforce_connection():
29
+ # Fetch Salesforce credentials from environment variables
30
+ sf = Salesforce(
31
+ username=os.getenv('SALESFORCE_USERNAME', 'your_username'),
32
+ password=os.getenv('SALESFORCE_PASSWORD', 'your_password'),
33
+ security_token=os.getenv('SALESFORCE_SECURITY_TOKEN', 'your_security_token')
34
+ )
35
+ return sf
36
 
37
  # OAuth flow to redirect to Salesforce login
38
  @app.route('/login')
 
61
 
62
  if token_response.status_code == 200:
63
  token_info = token_response.json()
64
+ access_token = token_info['access_token'] # Correct key to fetch the access token
65
+ instance_url = token_info['instance_url'] # Correct key to fetch the instance URL
66
 
67
  # Store access token in session for future API requests
68
  session['access_token'] = access_token
 
92
  else:
93
  return jsonify({"error": "Failed to fetch user info from Salesforce"}), 400
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