Spaces:
Sleeping
Sleeping
Update app.py
#2
by
Yaswanth56 - opened
app.py
CHANGED
|
@@ -20,13 +20,7 @@ CLIENT_SECRET = '36C463CD713C420BA2ED78F853359EACCE1ECCE2954C9810FFD7F946564CB0E
|
|
| 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')
|
| 25 |
-
def login():
|
| 26 |
-
oauth_url = f"{SALESFORCE_OAUTH_URL}?response_type=code&client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}"
|
| 27 |
-
return redirect(oauth_url)
|
| 28 |
|
| 29 |
-
# Handle the OAuth callback from Salesforce and exchange the authorization code for an access token
|
| 30 |
@app.route('/oauth/callback')
|
| 31 |
def oauth_callback():
|
| 32 |
auth_code = request.args.get('code') # The code returned from Salesforce
|
|
@@ -47,8 +41,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'] #
|
| 52 |
|
| 53 |
# Store access token in session for future API requests
|
| 54 |
session['access_token'] = access_token
|
|
@@ -58,6 +52,15 @@ def oauth_callback():
|
|
| 58 |
else:
|
| 59 |
return jsonify({"error": "Failed to authenticate with Salesforce"}), 400
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
# Example protected route that uses the Salesforce access token
|
| 62 |
@app.route('/dashboard')
|
| 63 |
def dashboard():
|
|
|
|
| 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 |
|
|
|
|
| 24 |
@app.route('/oauth/callback')
|
| 25 |
def oauth_callback():
|
| 26 |
auth_code = request.args.get('code') # The code returned from Salesforce
|
|
|
|
| 41 |
|
| 42 |
if token_response.status_code == 200:
|
| 43 |
token_info = token_response.json()
|
| 44 |
+
access_token = token_info['sSSjyhInIsUohKpG8sHzty2q'] # Correctly fetch the access token
|
| 45 |
+
instance_url = token_info['https://biryanihub-dev-ed.develop.my.site.com/s/welcomePage'] # Correctly fetch the instance URL
|
| 46 |
|
| 47 |
# Store access token in session for future API requests
|
| 48 |
session['access_token'] = access_token
|
|
|
|
| 52 |
else:
|
| 53 |
return jsonify({"error": "Failed to authenticate with Salesforce"}), 400
|
| 54 |
|
| 55 |
+
|
| 56 |
+
# OAuth flow to redirect to Salesforce login
|
| 57 |
+
//@app.route('/login')
|
| 58 |
+
def login():
|
| 59 |
+
oauth_url = f"{SALESFORCE_OAUTH_URL}?response_type=code&client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}"
|
| 60 |
+
return redirect(oauth_url)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
|
| 64 |
# Example protected route that uses the Salesforce access token
|
| 65 |
@app.route('/dashboard')
|
| 66 |
def dashboard():
|