I'm facing an issue I can't seems to fix, despite having tried everything I could.
I'm using Flask + Flask_oauthlib to connect to SalesForce. Here's my code :
from flask import Flask, url_for
from flask_oauthlib.client import OAuth
app = Flask(__name__)
oauth = OAuth(app)
salesforce = oauth.remote_app('salesforce',
consumer_key='my_consumer_key',
# grant_type='authorization_code',
consumer_secret='my_consumer_secret',
request_token_url='https://login.salesforce.com/services/oauth2/token',
access_token_url='https://login.salesforce.com/services/oauth2/token',
authorize_url='https://login.salesforce.com/services/oauth2/authorize')
@app.route('/')
def home():
url = url_for('oauth', _external=True)
salesforce.authorize(callback=url)
return 'ok'
@app.route('/oauth')
def oauth():
resp = salesforce.authorized_response()
print resp
return 'ok'
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
When I run this and goes to /
, I get the following exception :
OAuthException: Failed to generate request token
I added an output from the line in question where the exception is thrown ("/usr/lib64/python2.7/site-packages/flask_oauthlib/client.py", line 580), and this is the response from Salesforce :
{u'error_description': u'grant type not supported', u'error': u'unsupported_grant_type'}
So apparently I need to set the grant_type
to something allowed.
I tried to add the grant_type as you can see in the commented section, but when I restart the code, it stops with the following error :
TypeError: init() got an unexpected keyword argument 'grant_type'
Yay ...
I took a look, and applied the answers from the following questions, without any luck :
- https://salesforce.stackexchange.com/questions/34928/oauth2-token-request-using-json-fails-grant-type-not-supported
- Salesforce returning "unsupported_grant_type"
- Salesforce Authentication Failing
Does anyone has an idea about why I have this issue ?