# Issue with python authlib and content-type header

**URL:** <https://devforum.okta.com/t/issue-with-python-authlib-and-content-type-header/12272>\
**Category:** Questions\
**Created:** [December 28, 2020, 2:46am UTC](https://devforum.okta.com/t/issue-with-python-authlib-and-content-type-header/12272 "2020-12-28T02:46:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jon\_k](https://avatars.discourse-cdn.com/v4/letter/j/7cd45c/32.png) [@jon\_k](https://devforum.okta.com/u/jon_k)\
**Post date:** [December 28, 2020, 2:46am UTC](https://devforum.okta.com/t/issue-with-python-authlib-and-content-type-header/12272/1 "2020-12-28T02:46:16Z")

</div>

I am trying to setup a flask server because the underlying library outlined in [oktas guide](https://developer.okta.com/blog/2018/07/12/flask-tutorial-simple-user-registration-and-login) is abandoned and has security problems.

So I found a supported library called authlib with flask support.

Here’s how I instance the library

```
from authlib.integrations.flask_client import OAuth

oauth = OAuth(app)
oauth.register(
    name='oidc_client',#'okta',
    client_id='xxxx',
    client_secret='yyyyyyyyyy',
    request_token_url='https://dev-1.okta.com/oauth2/default/v1/token',
    access_token_url='https://dev-1.okta.com/oauth2/default/v1/token',
    #access_token_url='https://dev-1.okta.com/oauth2/default/v1/authorize', # i tried this too
    authorize_url='https://dev-1.okta.com/oauth2/default/v1/authorize',
    api_base_url='https://dev-1.okta.com/oauth2/',
)

```

The problem happens when I try to authenticate I get this error:

authlib.integrations.base\_client.errors.OAuthError: fetch\_token\_denied: Token request failed with code 400, response was ‘{“errorCode”:“E0000021”,“errorSummary”:“Bad request. Accept and/or Content-Type headers likely do not match supported values.”,“errorLink”:“E0000021”,“errorId”:“oaeHlsSPdOrQ-K0\_5iOT0nnhA”,“errorCauses”:}’.

Any ideas? Are there overrides I can set to fix the header? Is it related to this? ```

> **[OAuth 2 Session](https://docs.authlib.org/en/latest/client/oauth2.html#compliance-fix-for-non-standard)**
>
> An OAuth 2.0 Client implementation for Python requests, and httpx, powered by Authlib.

```auto

```

---

<div class="post-metadata">

**Author:** ![jon\_k](https://avatars.discourse-cdn.com/v4/letter/j/7cd45c/32.png) [@jon\_k](https://devforum.okta.com/u/jon_k)\
**Post date:** [December 28, 2020, 6:31pm UTC](https://devforum.okta.com/t/issue-with-python-authlib-and-content-type-header/12272/2 "2020-12-28T18:31:44Z")

</div>

For anyone stuck where I was, here is the proper settings I used to overcome my issues. The issue was request\_token\_url makes the library use oauth 1.0 I think.

After this you should be able to retrieve the profile credentials and whatnot and use a flask session object to store them securely.

```
oauth.register(
    name='oidc_client',#'okta',
    client_id='xxxxx',
    client_secret='yyyyy',
    access_token_url='https://dev-1.okta.com/oauth2/default/v1/token',
    authorize_url='https://dev-1.okta.com/oauth2/default/v1/authorize',
    redirect_uri='http://localhost:5000/authorize',
    api_base_url='https://dev-1.okta.com/oauth2/',
    client_kwargs={'scope': 'openid'}
)
```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [December 29, 2020, 6:43pm UTC](https://devforum.okta.com/t/issue-with-python-authlib-and-content-type-header/12272/3 "2020-12-29T18:43:41Z")

</div>

Closed on December 29, 2020, 6:43pm UTC

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
