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: Support Bearer Token Authentication #165

Merged
merged 12 commits into from
Nov 2, 2020
Merged

Conversation

dzleidig
Copy link
Contributor

@dzleidig dzleidig commented Jun 25, 2020

We will soon be passing a client_credentials (service-to-service) bearer token to programs when executing in the context of Igor. Web will validate the bearer token (and only the bearer token, no user token needed) when receiving an API request.

Programs internally call the transcriptic library (this repo) to form an API Connection.

The change in this PR involves changing the Connection instantiation routine to recognize if the token is a Bearer token and, if so, set the standard OAuth Authorization header (and no X-User-Token header). This is opposed to a non-bearer token, which will result in the usual X-User-Token header.

Jira Issue: SEA-271

@dzleidig dzleidig requested a review from yangchoo June 25, 2020 23:38
Copy link
Contributor

@yangchoo yangchoo left a comment

Choose a reason for hiding this comment

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

I think this is generally fine as a workaround, but I would like us to consider putting in more design work around this, especially if we foresee adding more authentication types (e.g. OAuth) in the future.

yangchoo
yangchoo previously approved these changes Jul 7, 2020
Copy link
Contributor

@yangchoo yangchoo left a comment

Choose a reason for hiding this comment

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

Had a discussion where it was decided that its fine to overload the token field for now.

The main decision point here is that we do not have upcoming authentication types in the horizon.

yangchoo
yangchoo previously approved these changes Jul 9, 2020
Copy link
Contributor

@yangchoo yangchoo left a comment

Choose a reason for hiding this comment

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

lgtm, thanks for adding in the validations

@dzleidig
Copy link
Contributor Author

I'll take a final round of review on this when you get a chance, @yangchoo.

I'm getting some lint errors on Travis, but I did not change these files and I have latest master merged into my branch:

black....................................................................Failed
- hook id: black
- files were modified by this hook
reformatted /home/travis/build/strateos/transcriptic/transcriptic/analysis/spectrophotometry.py
reformatted /home/travis/build/strateos/transcriptic/transcriptic/cli.py
reformatted /home/travis/build/strateos/transcriptic/transcriptic/commands.py
reformatted /home/travis/build/strateos/transcriptic/transcriptic/routes.py

@dzleidig dzleidig requested a review from yangchoo October 26, 2020 17:10
@yangchoo
Copy link
Contributor

@dzleidig the issue with the local lint is due to a mismatch between your local black version and what's used in Travis. #168 should address this issue.

Copy link
Contributor

@yangchoo yangchoo left a comment

Choose a reason for hiding this comment

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

the core logic seems straightforward enough (adding to the authorization headers).

Minor nits on some extraneous keys. Additional clarification/messaging around specification of multiple tokens would be good as well.

@dzleidig dzleidig requested a review from yangchoo October 27, 2020 17:04
yangchoo
yangchoo previously approved these changes Oct 28, 2020
Copy link
Contributor

@yangchoo yangchoo left a comment

Choose a reason for hiding this comment

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

Thanks for addressing nits. New behavior for handling token/bearer-token case looks good to me.

Please rebase w/ master to address the CI-lint errors.

@dzleidig
Copy link
Contributor Author

dzleidig commented Oct 29, 2020

Hmm, after installing the extra dependencies (e.g. pip install '.[docs]'`), the pre-commit passes locally without issue:

~/dev/transcriptic  SEA-271-oauth-token ✗                                                                                                                                                             1d ◒  
▶ pre-commit run --all-files                            
Check Yaml...............................................................Passed
Fix End of Files.........................................................Passed
Trim Trailing Whitespace.................................................Passed
black....................................................................Passed
Pylint...................................................................Passed
(env) 

@yangchoo
Copy link
Contributor

Can confirm that I'm unable to reproduce this issue locally. After doing some further digging, I suspect it may be related to pylint concurrency. Based on pylint-dev/pylint#3611

I pushed a commit to limit the concurrency to 1 for now.

Let's see if this works. There's a big backlog on travis right now, so things are slower than usual on that front.

@yangchoo
Copy link
Contributor

Seems like the concurrency limitations didn't fix the issue. For now, adding an explicit ignore so that it doesn't block this diff. Something to continue to look into

@dzleidig
Copy link
Contributor Author

Ah, that's too bad. Can you approve once again so I can merge?

@yangchoo yangchoo force-pushed the SEA-271-oauth-token branch from 78c5f9e to 887f3cc Compare November 2, 2020 02:09
@yangchoo yangchoo force-pushed the SEA-271-oauth-token branch from 887f3cc to 7226275 Compare November 2, 2020 02:15
Copy link
Contributor

@yangchoo yangchoo left a comment

Choose a reason for hiding this comment

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

Formal approval. Lint error seems to have been fixed after reverting accidental comment change.

@yangchoo yangchoo merged commit e2014ed into master Nov 2, 2020
@yangchoo yangchoo deleted the SEA-271-oauth-token branch November 2, 2020 02:27
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