Question

Python to get API using OAuth2: Authorization code + Implicit Grant Type

  • 21 March 2024
  • 0 replies
  • 68 views

I’m trying to get a token using python and authenticating via OAuth2 with the “Authorization code + Implicit Grant Type” check box checked. My code is as follows:

 

client_id = r'[Client ID]'

client_secret = r'[Client Secret]'



auth_url = "https://[OurDomain]/oauth2/authorize"

redirect_uri = "https://[OurDomain]"

token_url = "https://[OurDomain]/oauth2/token"

 

oauth = requests_oauthlib.OAuth2Session(client_id, redirect_uri=redirect_uri)

 

# Redirect user to Docebo for authorization

authorization_url, state = oauth.authorization_url(auth_url)

print('Please go here and authorize: ', authorization_url)

authorization_response = input('Enter the full callback URL')

token = oauth.fetch_token(

        token_url,

        #authorization_response=authorization_response,

        code=authorization_response,

        client_secret=client_secret)

I seem to successfully make my way to the portion where I get the token. I do feel like I’m unsure of the callback URL I should be passing in for code. I’ve tried several variations of the authorization_url and all result in the following error: 

oauthlib.oauth2.rfc6749.errors.InvalidGrantError: (invalid_grant) Authorization code doesn't exist or is invalid for the client

 


0 replies

Be the first to reply!

Reply