Flask OIDC: oauth2client.client.FlowExchangeError

2024/10/8 22:15:46

The Problem:

The library flask-oidc includes the scope parameter into the authorization-code/access-token exchange request, which unsurprisingly throws the following error:

oauth2client.client.FlowExchangeError: invalid_request Scope parameter is not supported on an authorization code access_token exchange request. Scope parameter should be supplied to the authorized request.

The Question:

Is this a configuration problem or a library problem?

My Configurations:

  • Flask Application:
app.config.update({'DEBUG': True,'TESTING': True,'SECRET_KEY': 'secret','SERVER_NAME' : 'flask.example.com:8000','OIDC_COOKIE_SECURE': False,'OIDC_REQUIRE_VERIFIED_EMAIL': False,'OIDC_CALLBACK_ROUTE': '/oidc/callback','OIDC_CLIENT_SECRETS': 'client_secrets.json'
})
oidc = OpenIDConnect(app)
  • client_secrets.json
{"web": {"auth_uri": "http://openam.example.com:8080/openam/oauth2/realms/root/authorize","issuer": "http://openam.example.com:8080/openam/oauth2/realms/root/","userinfo_uri": "http://openam.example.com:8080/openam/oauth2/realms/root/userinfo","client_id": "MyClientID","client_secret": "password","redirect_uris": ["http://flask.example.com:8000/oidc/callback"],"token_uri": "http://openam.example.com:8080/openam/oauth2/realms/root/token","token_introspection_uri": "http://openam.example.com:8080/openam/oauth2/realms/root/introspect"}
}
  • Access Manager

For the access manager I use OpenAM. I configured an OpenAM client agent as follows:

  • Client ID = MyClientID
  • Client Secret = password
  • Response Type = code
  • Token Endpoint Authentication Method = client_secret_post
  • Redirect URI = http://flask.example.com:8000/oidc/callback

Context: I use flask-oidc for the logic on the application side and OpenAM for the identity and access management - both applications run in docker containers. When using simple curl commands I can retrieve an authorization grant as well as an authentication token (grant type: Authorization Code Grant). However, using the mentioned library, after logging in to OpenAM and granting authorization to the application (endpoint 'oauth2/authorize'), flask-oidc sends the following GET request:

GET /oidc/callback?code=<some code> \
&scope=openid%20email \
&iss=http%3A%2F%2Fopenam.example.com%3A8080%2Fopenam%2Foauth2 \
&state=<some state> \
&client_id=MyClientID

Which leads to the error mentioned above.

Answer

While this does not directly answer the question, the best answer I could find was to use pyJWT or oauthlib instead of using flask-oidc. I found pyjwt was very straightforward in most respects, and there is an excellent tutorial here:

SSO Using Flask Request Oauthlib and pyjwt

I am not sure of this, but because the error is generated by oauth2client, not flask-oidc, it is possible the error is actually just related to the deprecated oathlib2clientlib.

There was a detailed request to mark the entire flask-oidc project as deprecated, but that request was made several years after the flask-oidc project was stopped being maintained. I hope one day flask will roove this link from their site because it is misleading to think that it is a main part of flask.

https://en.xdnf.cn/q/70093.html

Related Q&A

Cumulative count at a group level Python

I have a pandas dataframe like this : df = pd.DataFrame([[A, 1234, 20120201],[A, 1134, 20120201],[A, 1011, 20120201],[A, 1123, 20121004],[A, 1111, 20121004],[A, 1224, 20121105],[B, 1156, 20120403],[B, …

Easiest ways to generate graphs from Python? [closed]

Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.We don’t allow questi…

Stripping python namespace attributes from an lxml.objectify.ObjectifiedElement [duplicate]

This question already has answers here:Closed 11 years ago.Possible Duplicate:When using lxml, can the XML be rendered without namespace attributes? How can I strip the python attributes from an lxml…

matplotlib xkcd and black figure background

I am trying to make a plot using matplotlibs xkcd package while having a black background. However, xkcd seems to add a sort of white contour line around text and lines. On a white background you cant …

Python: Whats the difference between set.difference and set.difference_update?

s.difference(t) returns a new set with no elements in t.s.difference_update(t) returns an updated set with no elements in t.Whats the difference between these two set methods? Because the difference_u…

python telebot got unexpected response

I have been using my Telegram bot for sending me different notifications from my desktop computer using pythons telebot library. Everything was working properly for quite a long time, but one day it st…

How to set correct value for Django ROOT_URLCONF setting in different branches

Ive put site directory created by django-admin startproject under version control (Mercurial). Lets say, the site is called frobnicator.Now I want to make some serious refactoring, so I clone the site …

How do I improve scrapys download speed?

Im using scrapy to download pages from many different domains in parallel. I have hundreds of thousands of pages to download, so performance is important.Unfortunately, as Ive profiled scrapys speed, …

Convert numpy, list or float to string in python

Im writing a python function to append data to text file, as shown in the following,The problem is the variable, var, could be a 1D numpy array, a 1D list, or just a float number, I know how to convert…

Shared XMPP connection between Celery workers

My web app needs to be able to send XMPP messages (Facebook Chat), and I thought Celery might be a good solution for this. A task would consist of querying the database and sending the XMPP message to …