Skip to content

Conversation

@MarcGraham
Copy link
Contributor

@MarcGraham MarcGraham commented Sep 25, 2020

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.

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
…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
Remove redundant this.adapter
Use part of authentication object for authData
Typos and capitolization
Copy link
Contributor

@mrstegeman mrstegeman left a 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.


for (const i in this.adapter.authData) {
if (this.wsUrl.includes(i)) {
switch (this.adapter.authData[i].method) { // 0 is the method - jwt etc
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

performAction(action) {
action.start();

const headers = this.adapter.getHeaders(this.actionsUrl);
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

// add auth to query string
let auth = '';

for (const i in this.adapter.authData) {
Copy link
Contributor

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))

Copy link
Contributor Author

@MarcGraham MarcGraham Oct 2, 2020

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.

if (contentType) {
headers['Content-Type'] = 'application/json';
}
for (const i in this.authData) {
Copy link
Contributor

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))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this too

for (const url of config.urls) {
if ('authentication' in url) {
// remove http(s) from url
let url_stub = '';
Copy link
Contributor

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

Copy link
Contributor Author

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
@mrstegeman mrstegeman merged commit fad2a65 into WebThingsIO:master Oct 2, 2020
@MarcGraham
Copy link
Contributor Author

Sweet -- nice to see it in.

I noticed something that could be simplified at line 858

Screen Shot 2020-10-02 at 9 38 20 AM

Can probably just be

adapter.authData[urlStub] = url.authentication;

@mrstegeman
Copy link
Contributor

Good call. Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants