Skip to content

Commit

Permalink
Fix url parsing bug (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogebrd authored Oct 19, 2020
1 parent e1feb3c commit fd3e4ee
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ npm install --save-dev dropbox-oauth-popup
Or you can use it directly in your browser be including the following tag

```
<script src="https://cdn.jsdelivr.net/npm/dropbox-oauth-popup@1.3.0"></script>
<script src="https://cdn.jsdelivr.net/npm/dropbox-oauth-popup@1.3.1"></script>
```

## License
Expand Down
4 changes: 2 additions & 2 deletions examples/browser.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@7/dist/polyfill.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/2.0.3/fetch.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dropbox/dist/Dropbox-sdk.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dropbox-oauth-popup@1.3.0/dist/dropboxPopup.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dropbox-oauth-popup@1.3.1/dist/dropboxPopup.js"></script>
</head>

<body>
Expand All @@ -15,7 +15,7 @@ <h1>Dropbox OAuth Popup Window</h1>
See the Dropbox OAuth Popup Window in action by clicking the run example button.
This example will authenticate with your Dropbox account and use the token to fetch
the current account using the `users.getCurrentAccount` endpoint. (Note, nothing is
saved on our end, this is just a demo.)
saved, this is just a demo.)
</p>
<p>See the code on <a
href="https://github.com/rogebrd/dropbox-oauth-popup/blob/main/examples/browser.html">GitHub</a></p>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dropbox-oauth-popup",
"version": "1.3.0",
"version": "1.3.1",
"registry": "npm",
"description": "This is a simple addition built onto the Dropbox SDK that allows for OAuth in the browser to be done via a popup window.",
"homepage": "https://github.com/rogebrd/dropbox-oauth-popup",
Expand Down
6 changes: 3 additions & 3 deletions src/dropboxPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { DropboxAuth } from 'dropbox';
* main window.
*/
function dispatchResult() {
const params = window.location.href;
const params = window.location.search;
if (window.opener) {
// send them to the opening window
window.opener.postMessage(params);
Expand Down Expand Up @@ -37,7 +37,6 @@ export default class DropboxPopup {
clientSecret: this.clientSecret,
});
this.redirectUri = options.redirectUri;
this.codeOffset = this.redirectUri.length + 7; // format is `${redirectUri}/?code={code}
}

/**
Expand Down Expand Up @@ -65,7 +64,8 @@ export default class DropboxPopup {
*/
handleRedirect(event) {
const { data } = event;
const code = data.substring(this.codeOffset);
const urlParams = new URLSearchParams(data);
const code = urlParams.get('code');
this.authObject.getAccessTokenFromCode(this.redirectUri, code)
.then((response) => {
const { result } = response;
Expand Down

0 comments on commit fd3e4ee

Please sign in to comment.