Skip to content
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

feat: implemented native authentication with pwa using auth0 API #343

Merged
merged 6 commits into from
Jun 8, 2021
Merged

feat: implemented native authentication with pwa using auth0 API #343

merged 6 commits into from
Jun 8, 2021

Conversation

vickywane
Copy link
Contributor

@vickywane vickywane commented Mar 30, 2021

Purpose

This PR implements a native authentication with a user's PWA, as a requirement for the premium user feature

Approach

Work done here fetches the user's access_token from auth0 after the user's consent from the PWA.

This design diagram shows how the notification feature is being implemented in this Pull Request and also how it integrates with the connected PWA.

edge-device-pwa-sync-flow (5)

Merge Checklist

  • The code change is tested and works locally.
  • The user and dev documentation is up to date.
  • There is no commented-out code in this PR.
  • No lint errors (use flake8)
  • 100% test coverage

@commit-lint
Copy link

commit-lint bot commented Mar 30, 2021

Features

  • added new auth endpoint (2199ca3)

Bug Fixes

Contributors

vickywane

Commit-Lint commands

You can trigger Commit-Lint actions by commenting on this PR:

  • @Commit-Lint merge patch will merge dependabot PR on "patch" versions (X.X.Y - Y change)
  • @Commit-Lint merge minor will merge dependabot PR on "minor" versions (X.Y.Y - Y change)
  • @Commit-Lint merge major will merge dependabot PR on "major" versions (Y.Y.Y - Y change)
  • @Commit-Lint merge disable will desactivate merge dependabot PR
  • @Commit-Lint review will approve dependabot PR
  • @Commit-Lint stop review will stop approve dependabot PR

@pep8speaks
Copy link

pep8speaks commented Mar 30, 2021

Hello @vickywane! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 35:80: E501 line too long (93 > 79 characters)

Line 11:80: E501 line too long (90 > 79 characters)
Line 74:80: E501 line too long (81 > 79 characters)

Line 77:80: E501 line too long (103 > 79 characters)

Comment last updated at 2021-05-20 11:00:22 UTC

@lgtm-com
Copy link

lgtm-com bot commented Mar 30, 2021

This pull request introduces 8 alerts when merging 911e583 into 440cebc - view on LGTM.com

new alerts:

  • 4 for Unused local variable
  • 4 for Unused import

@ivelin
Copy link
Collaborator

ivelin commented Mar 30, 2021

@vickywane the CI checks are failing. Let me know when all checks pass.

I would also like to review simultaneously the UI PR that handles user authorization approval for this edge device.

@lgtm-com
Copy link

lgtm-com bot commented Mar 31, 2021

This pull request introduces 3 alerts when merging 18c263b into 440cebc - view on LGTM.com

new alerts:

  • 2 for Unused import
  • 1 for Unused local variable

@lgtm-com
Copy link

lgtm-com bot commented Mar 31, 2021

This pull request introduces 3 alerts when merging e5e770d into 440cebc - view on LGTM.com

new alerts:

  • 2 for Unused import
  • 1 for Unused local variable

@codecov
Copy link

codecov bot commented Mar 31, 2021

Codecov Report

Merging #343 (baed1d8) into master (440cebc) will increase coverage by 0.04%.
The diff coverage is 96.36%.

❗ Current head baed1d8 differs from pull request most recent head bccf6d8. Consider uploading reports for the commit bccf6d8 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #343      +/-   ##
==========================================
+ Coverage   94.56%   94.61%   +0.04%     
==========================================
  Files          23       23              
  Lines        2228     2264      +36     
==========================================
+ Hits         2107     2142      +35     
- Misses        121      122       +1     
Impacted Files Coverage Δ
src/ambianic/notification.py 88.60% <93.10%> (+5.27%) ⬆️
src/ambianic/__init__.py 100.00% <100.00%> (ø)
src/ambianic/pipeline/store.py 97.00% <100.00%> (-1.98%) ⬇️
src/ambianic/webapp/flaskr.py 88.46% <100.00%> (+0.74%) ⬆️

@lgtm-com
Copy link

lgtm-com bot commented Mar 31, 2021

This pull request introduces 4 alerts when merging 44b96e6 into 440cebc - view on LGTM.com

new alerts:

  • 2 for Unused import
  • 1 for Unused local variable
  • 1 for Except block handles 'BaseException'

Copy link
Collaborator

@ivelin ivelin left a comment

Choose a reason for hiding this comment

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

@vickywane the codecov check does not pass. This PR doesn't have a single test to cover the new code.

See other comments inline.

src/ambianic/pipeline/store.py Outdated Show resolved Hide resolved
src/ambianic/pipeline/store.py Outdated Show resolved Hide resolved
src/ambianic/pipeline/store.py Show resolved Hide resolved
src/ambianic/pipeline/store.py Show resolved Hide resolved
src/ambianic/webapp/flaskr.py Outdated Show resolved Hide resolved
@lgtm-com
Copy link

lgtm-com bot commented Apr 2, 2021

This pull request introduces 5 alerts when merging 6c4595d into 440cebc - view on LGTM.com

new alerts:

  • 2 for Except block handles 'BaseException'
  • 2 for Unused import
  • 1 for Unused local variable

@lgtm-com
Copy link

lgtm-com bot commented Apr 2, 2021

This pull request introduces 5 alerts when merging 5163e0c into 440cebc - view on LGTM.com

new alerts:

  • 2 for Except block handles 'BaseException'
  • 2 for Unused import
  • 1 for Unused local variable

@lgtm-com
Copy link

lgtm-com bot commented Apr 2, 2021

This pull request introduces 4 alerts when merging c1fd0cf into 440cebc - view on LGTM.com

new alerts:

  • 2 for Unused import
  • 1 for Unused local variable
  • 1 for Except block handles 'BaseException'

@lgtm-com
Copy link

lgtm-com bot commented Apr 2, 2021

This pull request introduces 5 alerts when merging 091b2cb into 440cebc - view on LGTM.com

new alerts:

  • 2 for Except block handles 'BaseException'
  • 2 for Unused import
  • 1 for Unused local variable

@ivelin
Copy link
Collaborator

ivelin commented Apr 2, 2021

This design diagram shows how the notification feature is being implemented in this Pull Request and also how it integrates with the connected PWA.

@vickywane
I am not able to open this diagram. The URL points to an error.

Screen Shot 2021-04-02 at 5 56 42 PM

@vickywane
Copy link
Contributor Author

This design diagram shows how the notification feature is being implemented in this Pull Request and also how it integrates with the connected PWA.

@vickywane
I am not able to open this diagram. The URL points to an error.

Seems to be an issue with Draw. I just duplicated the diagram in a new document here

@ivelin
Copy link
Collaborator

ivelin commented Apr 2, 2021

This design diagram shows how the notification feature is being implemented in this Pull Request and also how it integrates with the connected PWA.

@vickywane
I am not able to open this diagram. The URL points to an error.

Seems to be an issue with Draw. I just duplicated the diagram in a new document here

OK. Added google doc comments.
Screen Shot 2021-04-02 at 6 21 35 PM

@vickywane
Copy link
Contributor Author

I am currently writing tests for the new API endpoints introduced as part of the edge-PWA auth flow.

The first endpoint (/user-code)has been covered with tests.

However, there's seems to be a limit to what can be tested. The /verify-token route returns a URL to a page containing a button that has to be manually clicked by a user before the authentication is complete. This cannot be done within the test suite except using simulation tests.

This also affects the third endpoint (/save-token). The authentication has be complete before a valid token is returned by auth0.

@lgtm-com
Copy link

lgtm-com bot commented Apr 3, 2021

This pull request introduces 5 alerts when merging 4196bf8 into 440cebc - view on LGTM.com

new alerts:

  • 2 for Except block handles 'BaseException'
  • 2 for Unused import
  • 1 for Unused local variable

@lgtm-com
Copy link

lgtm-com bot commented Apr 5, 2021

This pull request introduces 3 alerts when merging 33b5231 into 440cebc - view on LGTM.com

new alerts:

  • 2 for Unused import
  • 1 for Except block handles 'BaseException'

Copy link
Collaborator

@ivelin ivelin left a comment

Choose a reason for hiding this comment

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

I am currently writing tests for the new API endpoints introduced as part of the edge-PWA auth flow.

The first endpoint (/user-code)has been covered with tests.

However, there's seems to be a limit to what can be tested. The /verify-token route returns a URL to a page containing a button that has to be manually clicked by a user before the authentication is complete. This cannot be done within the test suite except using simulation tests.

This also affects the third endpoint (/save-token). The authentication has be complete before a valid token is returned by auth0.

Unit tests should not depend on third party services. Isolate and test your own code.
Worry about integration tests after you have full unit test coverage.

src/ambianic/webapp/flaskr.py Outdated Show resolved Hide resolved
src/ambianic/webapp/flaskr.py Outdated Show resolved Hide resolved
src/ambianic/webapp/flaskr.py Outdated Show resolved Hide resolved

return response

@app.route('/api/auth/save-token', methods=['POST'])
Copy link
Collaborator

Choose a reason for hiding this comment

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

All this new code needs to be covered with unit tests.

@ivelin
Copy link
Collaborator

ivelin commented Apr 5, 2021

@vickywane read a bit more how to create proper activity design diagrams. You have options, but whichever one you pick must communicate clearly who and when does what exactly:
https://drawio-app.com/create-uml-sequence-diagrams-in-draw-io/
https://www.diagrams.net/blog/swimlane-diagrams
https://nathanhumphrey.ca/posts/2021-01-11-bpmn-with-diagrams-net/

@vickywane
Copy link
Contributor Author

@vickywane read a bit more how to create proper activity design diagrams. You have options, but whichever one you pick must communicate clearly who and when does what exactly:
https://drawio-app.com/create-uml-sequence-diagrams-in-draw-io/
https://www.diagrams.net/blog/swimlane-diagrams
https://nathanhumphrey.ca/posts/2021-01-11-bpmn-with-diagrams-net/

Thank you.

I just expanded the document following guides from the articles above. The updated image is in the PR description above.

@ivelin
Copy link
Collaborator

ivelin commented Apr 5, 2021

@vickywane read a bit more how to create proper activity design diagrams. You have options, but whichever one you pick must communicate clearly who and when does what exactly:
https://drawio-app.com/create-uml-sequence-diagrams-in-draw-io/
https://www.diagrams.net/blog/swimlane-diagrams
https://nathanhumphrey.ca/posts/2021-01-11-bpmn-with-diagrams-net/

Thank you.

I just expanded the document following guides from the articles above. The updated image is in the PR description above.

The link in the PR description text points to an outdated document. Make sure the view and the link are in sync. Even better, make the PNG clickable and linking directly to the latest diagram source so it's easy to collaborate on it.

@vickywane
Copy link
Contributor Author

vickywane commented Apr 5, 2021

The link in the PR description text points to an outdated document. Make sure the view and the link are in sync. Even better, make the PNG clickable and linking directly to the latest diagram source so it's easy to collaborate on it.

The link has been fixed. It was becoming large so I had to use another means to export.

@lgtm-com
Copy link

lgtm-com bot commented Apr 6, 2021

This pull request introduces 5 alerts when merging 2ff1b12 into 440cebc - view on LGTM.com

new alerts:

  • 3 for Except block handles 'BaseException'
  • 2 for Unused import

@lgtm-com
Copy link

lgtm-com bot commented Apr 6, 2021

This pull request introduces 4 alerts when merging fa2ad11 into 440cebc - view on LGTM.com

new alerts:

  • 3 for Except block handles 'BaseException'
  • 1 for Unused import

@ivelin
Copy link
Collaborator

ivelin commented Apr 6, 2021

The link in the PR description text points to an outdated document. Make sure the view and the link are in sync. Even better, make the PNG clickable and linking directly to the latest diagram source so it's easy to collaborate on it.

The link has been fixed. It was becoming large so I had to use another means to export.

The link now points to a google doc, that does not allow comments....

@vickywane
Copy link
Contributor Author

The link now points to a google doc, that does not allow comments....

I have updated the file permission here.

@ivelin
Copy link
Collaborator

ivelin commented Apr 6, 2021

The link now points to a google doc, that does not allow comments....

I have updated the file permission here.

OK, I can comment now.

@lgtm-com
Copy link

lgtm-com bot commented May 10, 2021

This pull request introduces 1 alert when merging ec392a3 into 440cebc - view on LGTM.com

new alerts:

  • 1 for Except block handles 'BaseException'

Copy link
Collaborator

@ivelin ivelin left a comment

Choose a reason for hiding this comment

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

still a few open comment that are awaiting response

src/ambianic/pipeline/store.py Outdated Show resolved Hide resolved
@lgtm-com
Copy link

lgtm-com bot commented May 12, 2021

This pull request introduces 4 alerts when merging 7c4ddf1 into 440cebc - view on LGTM.com

new alerts:

  • 3 for Unused import
  • 1 for Except block handles 'BaseException'

@lgtm-com
Copy link

lgtm-com bot commented May 12, 2021

This pull request introduces 4 alerts when merging aecd2f4 into 440cebc - view on LGTM.com

new alerts:

  • 3 for Unused import
  • 1 for Except block handles 'BaseException'

@lgtm-com
Copy link

lgtm-com bot commented May 12, 2021

This pull request introduces 4 alerts when merging 054679e into 440cebc - view on LGTM.com

new alerts:

  • 3 for Unused import
  • 1 for Except block handles 'BaseException'

@lgtm-com
Copy link

lgtm-com bot commented May 12, 2021

This pull request introduces 4 alerts when merging e344c43 into 440cebc - view on LGTM.com

new alerts:

  • 3 for Unused import
  • 1 for Except block handles 'BaseException'

@lgtm-com
Copy link

lgtm-com bot commented May 12, 2021

This pull request introduces 1 alert when merging 67174b3 into 440cebc - view on LGTM.com

new alerts:

  • 1 for Except block handles 'BaseException'

@lgtm-com
Copy link

lgtm-com bot commented May 12, 2021

This pull request introduces 1 alert when merging f6a0d0c into 440cebc - view on LGTM.com

new alerts:

  • 1 for Except block handles 'BaseException'

@vickywane
Copy link
Contributor Author

still a few open comments that are awaiting response

I think I have responded and made adjustments to all raised comments.
Please mention me on any comment that has been skipped or not answered fully.

@ivelin
Copy link
Collaborator

ivelin commented May 16, 2021

Hello @vickywane! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 35:80: E501 line too long (93 > 79 characters)

Line 11:80: E501 line too long (90 > 79 characters)
Line 72:80: E501 line too long (81 > 79 characters)

Line 77:80: E501 line too long (103 > 79 characters)
Line 81:80: E501 line too long (82 > 79 characters)

Comment last updated at 2021-05-12 19:16:16 UTC

@vickywane please address these linting issues.

@ivelin
Copy link
Collaborator

ivelin commented May 16, 2021

I am currently writing tests for the new API endpoints introduced as part of the edge-PWA auth flow.

The first endpoint (/user-code)has been covered with tests.

However, there's seems to be a limit to what can be tested. The /verify-token route returns a URL to a page containing a button that has to be manually clicked by a user before the authentication is complete. This cannot be done within the test suite except using simulation tests.

This also affects the third endpoint (/save-token). The authentication has be complete before a valid token is returned by auth0.

@vickywane use mockups to emulate server side behavior.

https://changhsinlee.com/pytest-mock/
https://www.toptal.com/python/an-introduction-to-mocking-in-python

@vickywane
Copy link
Contributor Author

vickywane commented May 16, 2021

This also affects the third endpoint (/save-token). The authentication has be complete before a valid token is returned by auth0.

@vickywane use mockups to emulate server side behavior.

https://changhsinlee.com/pytest-mock/

https://www.toptal.com/python/an-introduction-to-mocking-in-python

This is an old and outdated comment. It was part of the previous implementation which has been discarded.

We no longer have those routes / endpoints in the codebase.

@lgtm-com
Copy link

lgtm-com bot commented May 17, 2021

This pull request introduces 1 alert when merging 1e4b19f into e7e963d - view on LGTM.com

new alerts:

  • 1 for Except block handles 'BaseException'

@lgtm-com
Copy link

lgtm-com bot commented May 17, 2021

This pull request introduces 1 alert when merging 0425a66 into e7e963d - view on LGTM.com

new alerts:

  • 1 for Except block handles 'BaseException'

@lgtm-com
Copy link

lgtm-com bot commented May 17, 2021

This pull request introduces 1 alert when merging 9704d71 into e7e963d - view on LGTM.com

new alerts:

  • 1 for Except block handles 'BaseException'

@lgtm-com
Copy link

lgtm-com bot commented May 18, 2021

This pull request introduces 1 alert when merging a3c6b97 into 0291b2a - view on LGTM.com

new alerts:

  • 1 for Except block handles 'BaseException'

@lgtm-com
Copy link

lgtm-com bot commented May 18, 2021

This pull request introduces 1 alert when merging 704b1b1 into 0291b2a - view on LGTM.com

new alerts:

  • 1 for Except block handles 'BaseException'

@lgtm-com
Copy link

lgtm-com bot commented May 18, 2021

This pull request introduces 1 alert when merging 2fb55f8 into 0291b2a - view on LGTM.com

new alerts:

  • 1 for Except block handles 'BaseException'

@lgtm-com
Copy link

lgtm-com bot commented May 18, 2021

This pull request introduces 1 alert when merging baed1d8 into 0291b2a - view on LGTM.com

new alerts:

  • 1 for Unused import

Copy link
Collaborator

@ivelin ivelin left a comment

Choose a reason for hiding this comment

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

Cleanup redundant notification code and address unresolved comments.

src/ambianic/notification.py Show resolved Hide resolved
@vickywane
Copy link
Contributor Author

As requested I have created the following issues to be immediately worked upon after this pull request is merged;

The following were created in the Cloud API repository as they would be implemented there;

Copy link
Collaborator

@ivelin ivelin left a comment

Choose a reason for hiding this comment

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

@vickywane looks good. merging.

@ivelin ivelin merged commit d82d998 into ambianic:master Jun 8, 2021
github-actions bot pushed a commit that referenced this pull request Jun 8, 2021
# [1.15.0](v1.14.7...v1.15.0) (2021-06-08)

### Bug Fixes

* fixed auth0 client ([bccf6d8](bccf6d8))
* undefined build errors ([f1d0aa2](f1d0aa2))

### Features

* added new auth endpoint ([2199ca3](2199ca3))
* implemented native authentication with pwa using auth0 API ([d82d998](d82d998)), closes [#343](#343)
@github-actions
Copy link

github-actions bot commented Jun 8, 2021

🎉 This PR is included in version 1.15.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

github-actions bot pushed a commit to ivelin/ambianic-edge that referenced this pull request Jun 24, 2021
# [1.12.0](v1.11.1...v1.12.0) (2021-06-24)

### Bug Fixes

* fixed auth0 client ([bccf6d8](bccf6d8))
* undefined build errors ([f1d0aa2](f1d0aa2))

### Features

* added new auth endpoint ([2199ca3](2199ca3))
* implemented native authentication with pwa using auth0 API ([d82d998](d82d998)), closes [ambianic#343](https://github.com/ivelin/ambianic-edge/issues/343)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants