'BOX API authentication get auth_code

I am trying to interact with the BOX API. I did multiple researches and I followed multiple tutorials on how to do it but I am missing a step... I need to get the auth_code in order to get the refresh_token and the access_token. From what I understood the auth_code comes as a parameter in the url after the authentication.

from boxsdk import OAuth2
SDK = OAuth2(
    client_id=CLIENTID,
    client_secret=CLIENTSECRET
)
auth_url, csrf_token = SDK.get_authorization_url('{}/api/oauth2/authorize?response_type=code&client_id={}&redirect_uri={}/folder/0'.format(ENPOINT, CLIENTID, ENPOINT))
TOKENS['auth_url'] = auth_url
TOKENS['csrf_token'] = csrf_token
requests.get(auth_url)

When I access by browser the url returned in auth_url it takes me to site like this: enter image description here.

And after I click manually in Grant access to Box it redirects me to the Box folder of my choice and the url is in the format: https://xxxxx.com/folder/0?code=zzzzz&state=yyyyy. My goal is to extract the zzzzz and I do not understand how to get it programmatically...

References:
https://developer.box.com/guides/authentication/oauth2/with-sdk/
https://github.com/box/box-python-sdk#box-python-sdk
https://www.youtube.com/watch?v=ha26tN8amI0

A little help would be of great value, thanks in advance



Solution 1:[1]

Partial Answer: You retrieve the code by doing the following. Just redirect:

auth_url, csrf_token = oauth.get_authorization_url('https://google.com')

You have to set your Redirect URIs in the dev console to https://google.com. In the URL that you get back is the code that you need.

Remaining Issue: The only problem is that you have to grant access manually. I still have to overcome that problem. Then would the problem be solved. Anyone have an idea how to grant access?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jeremy Caney