<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: OAuth2 via Python SDK and Django in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/OAuth2-via-Python-SDK-and-Django/m-p/521126#M25409</link>
    <description>&lt;P&gt;I can't offer help for Django in particular, as that's made by Dropbox, but I'll be happy to offer whatever guidance I can in general.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, I'll send this along as a feature request to make DropboxOAuth2Flow serializable though I can't promise if or when that might be implemented.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, you generally shouldn't need to serialize it though; you can just recreate it when needed. For instance, &lt;A href="https://github.com/dropbox/mdwebhook/blob/master/app.py#L38" target="_self"&gt;here's an example&lt;/A&gt; (albeit written for Flask, and for an older version of the Dropbox SDK, but the idea is the same) showing how the flow is recreated via the "get_flow" method, which is re-used in both steps.&lt;/P&gt;</description>
    <pubDate>Tue, 18 May 2021 16:47:53 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2021-05-18T16:47:53Z</dc:date>
    <item>
      <title>OAuth2 via Python SDK and Django</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/OAuth2-via-Python-SDK-and-Django/m-p/520964#M25407</link>
      <description>&lt;P&gt;Hi again,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I'm trying to implement the non-pkce authorization via the Python SDK using DropboxOAuth2Flow with redirects.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;View 1 creates the initial auth_flow object.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;def dp_auth_start(request):
   auth_flow = dropbox.DropboxOAuth2Flow(....use_pkce=False)
   return HttpRedirect(auth_flow.start())&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;View 2 is supposed to take in the servers reply after the user has authorized my app and then again ask for the access_token.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;def dp_auth_accepted(request):
   auth_flow.finish(request.GET)
   ... continue with code here&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;As expected view 2 will yield an error that auth_flow is undefined. Of course, because it has not been passed on from view 1 to view 2 and is not newly defined here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So my question is a hybrid one:&lt;/P&gt;
&lt;P&gt;1) How does the Python SDK account for object transfers in a Django setting?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Is there a way that DropboxOAuth2Flow objects will be serializable in the future? This would make things super easy.&lt;/P&gt;
&lt;P&gt;3) How would I pass a non-Django object that is not serializable from view 1 to view 2 in a feasible and secure way? I know I could use pickle but try not to (it's working but comes at a price I'm hardly willing to pay).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I really appreciate any help you can provide!&lt;/P&gt;
&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 09:37:19 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/OAuth2-via-Python-SDK-and-Django/m-p/520964#M25407</guid>
      <dc:creator>foxo1</dc:creator>
      <dc:date>2021-05-18T09:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: OAuth2 via Python SDK and Django</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/OAuth2-via-Python-SDK-and-Django/m-p/521126#M25409</link>
      <description>&lt;P&gt;I can't offer help for Django in particular, as that's made by Dropbox, but I'll be happy to offer whatever guidance I can in general.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, I'll send this along as a feature request to make DropboxOAuth2Flow serializable though I can't promise if or when that might be implemented.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, you generally shouldn't need to serialize it though; you can just recreate it when needed. For instance, &lt;A href="https://github.com/dropbox/mdwebhook/blob/master/app.py#L38" target="_self"&gt;here's an example&lt;/A&gt; (albeit written for Flask, and for an older version of the Dropbox SDK, but the idea is the same) showing how the flow is recreated via the "get_flow" method, which is re-used in both steps.&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 16:47:53 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/OAuth2-via-Python-SDK-and-Django/m-p/521126#M25409</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2021-05-18T16:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: OAuth2 via Python SDK and Django</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/OAuth2-via-Python-SDK-and-Django/m-p/521267#M25415</link>
      <description>&lt;P&gt;Hi &lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/10"&gt;@Greg-DB&lt;/a&gt;!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for your reply - it works perfectly now without any pickling or weird dictionary.&lt;/P&gt;&lt;P&gt;For anyone out there I'd like to share my code to help you out if need be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;@login_required
def dropbox_authorization(request):
    auth_flow = dropbox.DropboxOAuth2Flow(
        _APP_KEY, 
        _REDIRECT_URI, 
        request.session,
        'dropbox-auth-csrf-token', 
        _APP_SECRET, 
        _LOCALE, 
        'offline',
        use_pkce=False)
    return HttpResponseRedirect(auth_flow.start())


@login_required
def dropbox_authorization_success(request):
    def _get_flow(request):
        return dropbox.DropboxOAuth2Flow(
            _APP_KEY,
            _REDIRECT_URI,
            request.session,
            'dropbox-auth-csrf-token',
            _APP_SECRET, 
            _LOCALE)

    result = _get_flow(request).finish(request.GET)
    request.user.dp_refresh_token = result.refresh_token
    request.user.save()
    request.session['access_token'], request.session['expires_at'] = result.access_token, result.expires_at.isoformat()

    return #to the view of your liking&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 05:56:36 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/OAuth2-via-Python-SDK-and-Django/m-p/521267#M25415</guid>
      <dc:creator>foxo1</dc:creator>
      <dc:date>2021-05-19T05:56:36Z</dc:date>
    </item>
  </channel>
</rss>

