Welcome to the new Box Support website. Check out all the details here on what’s changed.

How do extract the authorization code from the redirect URL (Python SDK)?

New post

Comments

2 comments

  • jcleblanc

    Hi ,

     

    Under step 3 of that guide this will be the line that extracts the code that you need:

     

    code = request.args.get('code')

     

    You'll also need the state parameter that is the line below the above. Basically when you set the state you'll just set some string of data (you set this in step 1). Typically this might be an invoice number, random token, or some other piece of data that you can use to verify the request. The state will have that original value that you set, so just check the state against the same value that you originally set the csrf_token to in step 1.

     

    assert state == csrf_token

    You then capture the access token session and refresh token with this line:

     

    access_token, refresh_token = oauth.authenticate(code)

    I also have a working Flask / Python sample over at https://github.com/jcleblanc/box-examples/blob/master/python/samples/auth_oauth.py if you'd prefer to just grab that.

     

    Let me know if you run into any issues.

     

    - Jon 

    0
    Comment actions Permalink
  • Rhea Dsouza

    This is fine, but how do we do it without an application. I just want the auth code in my python script. I have no application, no website, just a python script. Or is it not possible i.e. we have to have an application that redirects us to box, where we have to click the access button and then it redirects us to our app url from where we can get the code. I basically just want the access token in my script(and its just a python script not connected to anything), please let me know a way to do that. Thanks.    

    0
    Comment actions Permalink

Please sign in to leave a comment.