-
Notifications
You must be signed in to change notification settings - Fork 17
Add jwt support for thing-url-adapter #96
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
Conversation
If url -- set auth to bearer with jwt If wss -- Add to query string Load jwt_auth object at start from jwt_auth.json file. In the same dir as addon hostname.local:port : token
move jwt_auth.json to .mozilla-iot/config
… config page. added secureThings property add to db as: <hostname>:<port> <jwt> with a space between
…496151126 Renamed getHeaders to getHeaders().
…496152411 Change query param for websocket to ?jwt=<token>
…497069312 remove unneeded ws==null check
…496936672 Modify manifest.json to collect parameters for jwt, basic and digest auth. Store in config. Update load thing to pull data for auth from config url data. Massaged functions as needed to accomodate the auth stuff. Only JWT is implemented in the adapter code. Stubs are in place to add basic and digest. Will have to add code at lines 52, 297, and 856
…497652290 #96 (comment) #96 (comment) Proper naming, remove unneeded comments, remove console.log of AUTH_DATA
…497654154 Add config file update to loadThingURLAdapter.
…497654154 Add 'none' to auth mehtods. On upgrade of config and authenticaton object is added with a method property of 'none'
…497691362 move getHeaders function and authData to ThingURLAdapter. Added adapter property to ThingURLDevice and set it in the constructor. Changed all the getHeader() call accordingly.
…497691362 Update read me with instructions for secure thing usage. Change rev to 5.0 in manifest and package.jsnon
…496149251 Types and grammar.
…496149251 Types and grammar.
Remove redundant this.adapter Use part of authentication object for authData Typos and capitolization
mrstegeman
left a comment
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're really close! Only very minor things now. Thanks for being patient with me.
thing-url-adapter.js
Outdated
|
|
||
| for (const i in this.adapter.authData) { | ||
| if (this.wsUrl.includes(i)) { | ||
| switch (this.adapter.authData[i].method) { // 0 is the method - jwt etc |
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.
nit: the comment here can be removed now
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.
done
thing-url-adapter.js
Outdated
| performAction(action) { | ||
| action.start(); | ||
|
|
||
| const headers = this.adapter.getHeaders(this.actionsUrl); |
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 one does need the Content-Type 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.
added
thing-url-adapter.js
Outdated
| for (const i in this.authData) { | ||
| if (this.authData.hasOwnProperty(i)) { | ||
| if (url.includes(i)) { | ||
| switch (this.authData[i].method) { // 0 is the method - jwt etc |
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.
Comment can be removed.
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.
removed
thing-url-adapter.js
Outdated
| // add auth to query string | ||
| let auth = ''; | ||
|
|
||
| for (const i in this.adapter.authData) { |
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 would be a little cleaner:
for (const [url, authData] of Object.entries(this.adapter.authData))
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.
updated -- this was actually helpful.
thing-url-adapter.js
Outdated
| if (contentType) { | ||
| headers['Content-Type'] = 'application/json'; | ||
| } | ||
| for (const i in this.authData) { |
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 would be a little cleaner, and would remove the need for the proceeding hasOwnProperty check:
for (const [url, authData] of Object.entries(this.adapter.authData))
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 too
thing-url-adapter.js
Outdated
| for (const url of config.urls) { | ||
| if ('authentication' in url) { | ||
| // remove http(s) from url | ||
| let url_stub = ''; |
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.
nit: urlStub instead of url_stub
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.
renamed
Correct getHeaders for eventsUrl and perfromAction Rename variable url_stub
|
Good call. Done. |

Will use token if one available.
Add Authorization header to requests, adds same header to query string -- ?Authorization=Bearer jwt -- for web socket connections.
Tokens can be entered in the thing-url-adapter config page. Use format hostname:port jwt with a space between
I was able to test everything except the performAction and cancelAction functions.