sookasa / box.py

Python client for Box
43 stars 25 forks source link

finish_authenticate_v2 error #4

Closed nlrosidi closed 10 years ago

nlrosidi commented 10 years ago

I have an issue with authenticating the user using the 'finish_authenticate_v2' function. Specifically, 'request.REQUEST['code']' is not working. What library are you importing? Assuming the library is imported correctly, will the 'code' from the url redirection be transferred automatically to request.REQUEST['code']?

Currently, if I replace request.REQUEST['code'] with the actual code, I can get obtain my access token. However, I do not want to hardcode anything.

I am terribly new at this, sorry if this is such an easy problem.

I have an stackoverflow post as well: http://stackoverflow.com/questions/20339261/how-to-grab-the-authorization-code-from-url-to-get-token-in-box-using-python/20339480?noredirect=1#20339480

tals commented 10 years ago

request.REQUEST['code'] is provided as an example, and would only work if you're in a Django request handler.

essentially, once you click 'approve' on Box's dialog, they will redirect you to a URL of your choosing (see their docs to see how to change that). They supply a HTTP GET parameter named 'code' to that url, which is what you use to call finish_authenticate_v2.

So for example, if you configured Box to hit http://www.myapp.com/finish_box, when you click on "approve", Box will issue a request that looks something like 'http://www.myapp.com/finish_box?code=code_goes_here&.....'

tals commented 10 years ago

See documentation here: http://developers.box.com/oauth/

nlrosidi commented 10 years ago

Thanks for the clarification. This may or may not be the appropriate forum to ask this question but I have a Django app already made and want to incorporate this API into my app. Is there anything I need to do to set up a Django request handler so that your code works out of the box?

Also, I see that Box issues a request that can look like '' http://www.myapp.com/finish_box?code=code_goes_here&.....', how would i grab the code and put it into the finish_authenticate_v2?

Thanks Nate

Nate

On Mon, Dec 2, 2013 at 3:34 PM, tals notifications@github.com wrote:

request.REQUEST['code'] is provided as an example, and would only work if you're in a Django request handler.

essentially, once you click 'approve' on Box's dialog, they will redirect you to a URL of your choosing (see their docs to see how to change that). They supply a HTTP GET parameter named 'code' to that url, which is what you use to call finish_authenticate_v2.

So for example, if you configured Box to hit http://www.myapp.com/finish_box, when you click on "approve", Box will issue a request that looks something like ' http://www.myapp.com/finish_box?code=code_goes_here&.....'

— Reply to this email directly or view it on GitHubhttps://github.com/sookasa/box.py/issues/4#issuecomment-29669707 .

tals commented 10 years ago

It's not the right forum, but for django, you need to do the following (more or less):

in urls.py, add a pattern routing. Say something like:

urlpatterns = patterns(
     ....
     (r'^finish_box', box_authentication_done),
     ...
)

and then in your views.py, have something like:

def box_authentication_done(request):
    code = request.REQUEST.get('code')
    ....

so if you hit /finish_box?code=1234 code will be '1234'

For anything more, please check django tutorials and forums. That library has no relation to Django :)