<?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 How to use oauth2 for dropbox via Javascript/HTML in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-use-oauth2-for-dropbox-via-Javascript-HTML/m-p/360774#M20553</link>
    <description>&lt;P&gt;Currently I am using the below code, but either No 'Access-Control-Allow-Origin' header or error 400 comes up everytime. I have looked for guides about&amp;nbsp;No 'Access-Control-Allow-Origin' header, but haven't found any of use. My goal is to just grab the users username so I can use it in combination with an app I have created.&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;PRE&gt;$('#LoginBtn').click(function () {
$.ajax({
url: Url,
data: {
client_id: "App_Key",
response_type: "code",
},
dataType: 'jsonp',
type: 'GET',
success: function(response) {
alert('Success!')
},
error: function(errorThrown) {
alert(errorThrown.error);
}})&lt;BR /&gt;});&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Tue, 20 Aug 2019 13:44:34 GMT</pubDate>
    <dc:creator>solsubzero</dc:creator>
    <dc:date>2019-08-20T13:44:34Z</dc:date>
    <item>
      <title>How to use oauth2 for dropbox via Javascript/HTML</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-use-oauth2-for-dropbox-via-Javascript-HTML/m-p/360774#M20553</link>
      <description>&lt;P&gt;Currently I am using the below code, but either No 'Access-Control-Allow-Origin' header or error 400 comes up everytime. I have looked for guides about&amp;nbsp;No 'Access-Control-Allow-Origin' header, but haven't found any of use. My goal is to just grab the users username so I can use it in combination with an app I have created.&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;PRE&gt;$('#LoginBtn').click(function () {
$.ajax({
url: Url,
data: {
client_id: "App_Key",
response_type: "code",
},
dataType: 'jsonp',
type: 'GET',
success: function(response) {
alert('Success!')
},
error: function(errorThrown) {
alert(errorThrown.error);
}})&lt;BR /&gt;});&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 20 Aug 2019 13:44:34 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-use-oauth2-for-dropbox-via-Javascript-HTML/m-p/360774#M20553</guid>
      <dc:creator>solsubzero</dc:creator>
      <dc:date>2019-08-20T13:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to use oauth2 for dropbox via Javascript/HTML</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-use-oauth2-for-dropbox-via-Javascript-HTML/m-p/360778#M20555</link>
      <description>&lt;P&gt;Based on your code here, it looks like you're attempting to access&amp;nbsp;&lt;A href="http://www.dropbox.com/oauth2/authorize" target="_blank"&gt;www.dropbox.com/oauth2/authorize&lt;/A&gt; via an ajax call, but it's actually a web page, not an API endpoint, so you shouldn't access it via ajax.&lt;/P&gt;
&lt;P&gt;You should send the user to the&amp;nbsp;&lt;A href="http://www.dropbox.com/oauth2/authorize" target="_blank"&gt;www.dropbox.com/oauth2/authorize&lt;/A&gt; page as a URL in their browser. There, they can choose whether or not to allow the app to connect to their account.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can find more information on how the OAuth flow works in &lt;A href="https://www.dropbox.com/developers/reference/oauth-guide" target="_self"&gt;the OAuth guide&lt;/A&gt;. You can find the information for using the&amp;nbsp;&lt;A href="http://www.dropbox.com/oauth2/authorize" target="_blank"&gt;www.dropbox.com/oauth2/authorize&lt;/A&gt; page in particular in &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#oauth2-authorize" target="_self"&gt;the documentation&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Also, for integrating with the&amp;nbsp;Dropbox API via JavaScript, I&amp;nbsp;recommend using &lt;A href="https://github.com/dropbox/dropbox-sdk-js" target="_self"&gt;the official&amp;nbsp;Dropbox API v2 JavaScript SDK&lt;/A&gt; if you can. It comes with &lt;A href="https://github.com/dropbox/dropbox-sdk-js/blob/master/examples/javascript/auth/index.html" target="_self"&gt;an example of using the app authorization flow&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2019 21:02:35 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-use-oauth2-for-dropbox-via-Javascript-HTML/m-p/360778#M20555</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2019-08-19T21:02:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to use oauth2 for dropbox via Javascript/HTML</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-use-oauth2-for-dropbox-via-Javascript-HTML/m-p/360885#M20561</link>
      <description>&lt;P&gt;Apologies, I don't think I explained my problem well.&lt;/P&gt;&lt;P&gt;Currently attempting to authenticate and get a users username via a webpage. This username will correspond to a list of links on that webpage.&lt;/P&gt;&lt;P&gt;Recently I created an app that works fine with communicating to dropbox via flutter and swift code.&lt;/P&gt;&lt;P&gt;I have tried many different solutions such as ajax, but they usually come up with&amp;nbsp;&lt;SPAN&gt;No 'Access-Control-Allow-Origin' header or error 400. I have also tried the official Dropbox API for Javascript, but it seems to have issues with&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;var&amp;nbsp;&lt;/SPAN&gt;fetch = require('isomorphic-fetch');&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Also, recently tried &lt;A title="code flow example" href="https://github.com/dropbox/dropbox-sdk-js/blob/master/examples/javascript/code_flow_example.js" target="_blank" rel="noopener"&gt;this&lt;/A&gt;&lt;A href="https://github.com/dropbox/dropbox-sdk-js/blob/master/examples/javascript/code_flow_example.js" target="_self"&gt;.&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The goal is only to authenticate and grab the users username and that username will be a link between my already created app and the webpage that I am working on.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2019 13:43:52 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-use-oauth2-for-dropbox-via-Javascript-HTML/m-p/360885#M20561</guid>
      <dc:creator>solsubzero</dc:creator>
      <dc:date>2019-08-20T13:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to use oauth2 for dropbox via Javascript/HTML</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-use-oauth2-for-dropbox-via-Javascript-HTML/m-p/360908#M20564</link>
      <description>&lt;P&gt;To get user information, such as their name or&amp;nbsp;Dropbox account ID, you should use &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#users-get_current_account" target="_self"&gt;the&amp;nbsp;/2/users/get_current_account API endpoint&lt;/A&gt;. (That's&amp;nbsp;&lt;A href="https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#usersGetCurrentAccount__anchor" target="_self"&gt;usersGetCurrentAccount&lt;/A&gt; in &lt;A href="https://github.com/dropbox/dropbox-sdk-js" target="_self"&gt;the official&amp;nbsp;Dropbox JavaScript SDK&lt;/A&gt;.)&lt;/P&gt;
&lt;P&gt;In order to make that API call though, you first need an access token for the user.&amp;nbsp;You can get an access token for the user by sending them through the OAuth app authorization flow (details and links in my previous comment). That involves sending them to the&amp;nbsp;Dropbox web page where they can choose whether or not to authorize your app. Unlike actual API calls, such as&amp;nbsp;/2/users/get_current_account, that step on the&amp;nbsp;&lt;A href="http://www.dropbox.com/oauth2/authorize" target="_blank"&gt;www.dropbox.com/oauth2/authorize&lt;/A&gt; web page cannot be done programmatically&amp;nbsp;via ajax.&lt;/P&gt;
&lt;P&gt;Regarding the issues you mentioned with the 'fetch' line, note that that example is for Node.js. If you're running in front-end browser JavaScript, that won't work. (There's &lt;A href="https://dropbox.github.io/dropbox-sdk-js/tutorial-Getting%20started.html" target="_self"&gt;more information on setting up different environments here.&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;So, the basic flow would be something like this:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The user arrives at your app's web page.&lt;/LI&gt;
&lt;LI&gt;Your app sends the user to the&amp;nbsp;Dropbox app authorization web page.&lt;/LI&gt;
&lt;LI&gt;The user approves your app.&lt;/LI&gt;
&lt;LI&gt;Dropbox sends the user back to your app's web page.&lt;/LI&gt;
&lt;LI&gt;Your app receives&amp;nbsp;the resulting access token.&lt;/LI&gt;
&lt;LI&gt;Your app uses the access token to make&amp;nbsp;Dropbox API calls as needed, e.g., to retrieve the&amp;nbsp;Dropbox account information.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 20 Aug 2019 14:43:04 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-use-oauth2-for-dropbox-via-Javascript-HTML/m-p/360908#M20564</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2019-08-20T14:43:04Z</dc:date>
    </item>
  </channel>
</rss>

