requests-oauthlib icon indicating copy to clipboard operation
requests-oauthlib copied to clipboard

Remove auth headers with LegacyApplicationClient?

Open ChaosKid42 opened this issue 7 years ago • 2 comments

I am trying to do the following:

oauth = OAuth2Session(client=LegacyApplicationClient(client_id=CLIENT_ID))
try:
  token = oauth.fetch_token(
    verify=VERIFY,
    token_url=TOKEN_URL,
    username=username, password=password, 
    client_id=CLIENT_ID,
    scope=SCOPE,
    client_secret=CLIENT_SECRET)
except InvalidGrantError:
  pass
except (MissingTokenError, ConnectionError) as e:
  print('Exception while calling auth_proxy: {}'.format(type(e)))

As you can see in the following debug output, it puts authentication information in the body and in the header. My OAuth-Provider (AD FS) does not like that. Is there any way I can disable authntication-headers?

DEBUG:requests_oauthlib.oauth2_session:Encoding client_id "***" with client_secret as Basic auth credentials.
DEBUG:requests_oauthlib.oauth2_session:Requesting url https://adfs.tld/oauth/token using method POST.
DEBUG:requests_oauthlib.oauth2_session:Supplying headers {'Accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'} and data {'grant_type': 'password', 'username': '***@gmail.com', 'password': '***, 'scope': 'openid', 'client_id': '***', 'client_secret': '***'}
DEBUG:requests_oauthlib.oauth2_session:Passing through key word arguments {'json': None, 'timeout': None, 'auth': <requests.auth.HTTPBasicAuth object at 0x7fa72e3b9dd8>, 'verify': False, 'proxies': None}.
DEBUG:urllib3.connectionpool:https://adfs.tld:443 "POST /oauth/token HTTP/1.1" 200 1356
DEBUG:requests_oauthlib.oauth2_session:Prepared fetch token request body grant_type=password&username=***%40gmail.com&password=***&scope=openid&client_id=***&client_secret=***

ChaosKid42 avatar Jul 12 '18 12:07 ChaosKid42

@jvanasco is working to handle this specific use-case. It will requires both oauthlib and requests-oauthlib changes. See https://github.com/oauthlib/oauthlib/issues/585#issuecomment-420942874 changes proposal

JonathanHuot avatar Sep 14 '18 06:09 JonathanHuot

Another incompatible provider: Flask OAuth 2.0 Server.

aparamon avatar Oct 10 '18 10:10 aparamon