-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cookie auth and custom header feature #814
Conversation
Codecov Report
@@ Coverage Diff @@
## main #814 +/- ##
==========================================
+ Coverage 65.20% 65.51% +0.31%
==========================================
Files 7 7
Lines 773 780 +7
==========================================
+ Hits 504 511 +7
Misses 269 269
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
test/unit/dropbox.js
Outdated
chai.assert.equal(COOKIE, dbx.rpcRequest.getCall(0).args[2]); | ||
}); | ||
|
||
it('errors if cookie auth is supplied an OAuth token', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is actually the behavior we want for cookie auth but can remove if not.
src/dropbox.js
Outdated
@@ -206,5 +215,10 @@ export default class Dropbox { | |||
if (this.pathRoot) { | |||
options.headers['Dropbox-API-Path-Root'] = this.pathRoot; | |||
} | |||
if (this.customHeaders) { | |||
for (const header in this.customHeaders) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
linter is failing from this line but I think this is actually the behavior we more or less want, can alter the code to satisfy linter but I feel like it just adds extra code for no reason. Can also ignore lint this line if we want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid linter, we don't want to do this
src/dropbox.js
Outdated
@@ -50,6 +51,8 @@ const b64 = typeof btoa === 'undefined' | |||
* should only be used for testing as scaffolding to avoid making network requests. | |||
* @arg {String} [options.domainDelimiter] - A custom delimiter to use when separating domain from | |||
* subdomain. This should only be used for testing as scaffolding. | |||
* @arg {Object} [options.customHeaders] - An object designed to set custom headers to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have some indication of what format this object should be in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also needs to be reflected in the TS types file or TS clients won't be able to use this
src/dropbox.js
Outdated
@@ -125,6 +129,11 @@ export default class Dropbox { | |||
break; | |||
case NO_AUTH: | |||
break; | |||
case COOKIE: | |||
if (this.auth.accessToken) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, just break. We don't need to explicitely check this
src/dropbox.js
Outdated
@@ -206,5 +215,10 @@ export default class Dropbox { | |||
if (this.pathRoot) { | |||
options.headers['Dropbox-API-Path-Root'] = this.pathRoot; | |||
} | |||
if (this.customHeaders) { | |||
for (const header in this.customHeaders) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid linter, we don't want to do this
src/dropbox.js
Outdated
@@ -50,6 +51,8 @@ const b64 = typeof btoa === 'undefined' | |||
* should only be used for testing as scaffolding to avoid making network requests. | |||
* @arg {String} [options.domainDelimiter] - A custom delimiter to use when separating domain from | |||
* subdomain. This should only be used for testing as scaffolding. | |||
* @arg {Object} [options.customHeaders] - An object designed to set custom headers to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also needs to be reflected in the TS types file or TS clients won't be able to use this
48e9b05
to
5fad8c2
Compare
src/dropbox.js
Outdated
if (this.customHeaders) { | ||
const headerKeys = Object.keys(this.customHeaders); | ||
headerKeys.forEach((header) => { | ||
if (this.customHeaders[header]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to check if it exists? Don't we know it exists if we just got the keys for the headers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I thought the linter wanted an 'if' statement but I just realized if I do it this way then the linter doesn't care.
@@ -177,6 +181,8 @@ export interface DropboxOptions { | |||
domain?: string; | |||
// A custom delimiter to use when separating domain subdomain. This should only be used for testing as scaffolding. | |||
domainDelimiter?: string; | |||
// An object (in the form property: string) designed to set custom headers to use during a request. | |||
customHeaders?: customHeaders; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just use object, we don't need a custom type for this
@@ -177,6 +181,8 @@ export interface DropboxOptions { | |||
domain?: string; | |||
// A custom delimiter to use when separating domain subdomain. This should only be used for testing as scaffolding. | |||
domainDelimiter?: string; | |||
// An object (in the form property: string) designed to set custom headers to use during a request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be more concise by saying something like an object of headers to their values
@@ -177,6 +181,8 @@ export interface DropboxOptions { | |||
domain?: string; | |||
// A custom delimiter to use when separating domain subdomain. This should only be used for testing as scaffolding. | |||
domainDelimiter?: string; | |||
// An object (in the form property: string) designed to set custom headers to use during a request. | |||
customHeaders?: customHeaders; | |||
} | |||
|
|||
export class DropboxResponseError<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is the template, you need to re-generate the sdk to get this into the generated code. Make sure your submodules are at the same place as main is (just pull from main in each repo)
5fad8c2
to
77b9bf8
Compare
Checklist
General Contributing
Is This a Code Change?
Validation
npm test
pass?npm run build
pass?npm run lint
pass?