I’m trying to create a streamlit app and using the code referenced in this article to create a login gated streamlit app.
I can successfully get a code from the /oauth2/v1/authorize endpoint. However, when I try to get an access token from the /oauth2/v1/token endpoint, I get the error: “401 Client Error: Unauthorized for url: https://{org-url}/oauth2/v1/token”
It’s a “Web Application” in Dashboard. The authentication method is client_secret_post. I’m using endpoints that are /oauth2/v1/authorize, /oauth2/v1/token and /oauth2/v1/keys because that’s what I see in OpenID: https://${org-url}/.well-known/openid-configuration OAuth: https://${org-url}/.well-known/oauth-authorization-server
Code snippet is below:
auth_code = base64.b64encode(f"{config['client_id']}:{config['client_secret']}".encode("utf-8")).decode('ascii')
theaders = {
# 'accept': 'application/json',
'Authorization': f'Basic {auth_code}',
'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
}
tdata = {
'client_id': config['client_id'],
'client_secret': config['client_secret'],
'grant_type': 'authorization_code',
'redirect_uri': config['redirect_uri'],
'code': code,
'state': state,
'scope': config['scope'],
}
ret = requests.post(config["token_endpoint"], headers=theaders, data=urlencode(tdata).encode("utf-8"))
On the Okta Dashboard logs, the error seen is:
Imo I’m using the right authorization code. It’s supposed to be 64 bit encoded client_id:client_secret and I followed the steps to generate it using linux command line before I used python code to generate it as seen in code.
Any idea what’s wrong? How can I fix this? Let me know if more information needed.