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

[Python] Conditionally set auth attributes #4988

Merged
merged 8 commits into from
Jan 16, 2020

Conversation

sebastien-rosset
Copy link
Contributor

@sebastien-rosset sebastien-rosset commented Jan 13, 2020

Fix for #3844:

Do not add auth parameter in HTTP request if auth parameter is set None
Add attribute to control which auth schemes can be used.
Currently, the python client obtains the list of security schemes that have been specified in the OAS spec, and automatically adds the authentication attributes in the header, cookie or query. This happens even if the parameters are unset. For example, the "Authorization" header may be set with an empty Bearer token:

'Authorization': 'Bearer '
With this PR, the bearer access token is no longer set if its value is None.

Tests performed:

Use OAS spec that specifies more than one security scheme for a given operation, e.g. OAuth2 and cookie
Generate the Python SDK using the master branch
Write a Python client that sets the cookie but not the OAuth2 access token
Invoke the client and verifies both auth attributes have been set (causing auth failure)
Generate the Python SDK using code from this PR
Invoke the client again, verify the auth parameters are set conditionally.

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@sebastien-rosset sebastien-rosset changed the title Enhance python API keys [Python] Conditionally set auth attributes Jan 13, 2020
@sebastien-rosset
Copy link
Contributor Author

@spacether
Copy link
Contributor

@sebastien-rosset how is this pull request different than your old one?

@sebastien-rosset
Copy link
Contributor Author

@sebastien-rosset how is this pull request different than your old one?

Based on feedback from @wing328, I have made the following changes to avoid any breaking change for existing users:

  • Retain the space after the api key prefix.
  • Retain the "api_key" and "api_key_prefix" variables
  • Don't add the OAuth2 access token as a input argument to the Configuration constructor, because it would be better to have a TokenSource. This could be done in a separate PR.

@sebastien-rosset
Copy link
Contributor Author

There seems to be an unrelated build issue:

Loading composer repositories with package information
Failed to clone the [email protected]:ybelenko/slim-token-authentication.git repository, try running in interactive mode so that you can enter your GitHub credentials

@spacether
Copy link
Contributor

@wing328 why should we keep the api_key_prefix data in a separate dict when that data is storing info about an api_key? If we store it there it would be a breaking change with fallback and it reduces the number or dicts that we use from two to one. That way questions like:

  • what value should I use for an api_key
  • what prefix is used when sending this key
    Can all be answered in the one api_key dict

@sebastien-rosset
Copy link
Contributor Author

@wing328 why should we keep the api_key_prefix data in a separate dict when that data is storing info about an api_key? If we store it there it would be a breaking change with fallback and it reduces the number or dicts that we use from two to one. That way questions like:

  • what value should I use for an api_key
  • what prefix is used when sending this key
    Can all be answered in the one api_key dict

My understanding is that we should split in two separate PRs: one that can go in master without breaking the backward compatibility (because master will be used as the basis for the next minor revision), and another PR that should go into the next release that can potentially break backward compatibility.

@spacether
Copy link
Contributor

@wing328 why should we keep the api_key_prefix data in a separate dict when that data is storing info about an api_key? If we store it there it would be a breaking change with fallback and it reduces the number or dicts that we use from two to one. That way questions like:

  • what value should I use for an api_key
  • what prefix is used when sending this key
    Can all be answered in the one api_key dict

My understanding is that we should split in two separate PRs: one that can go in master without breaking the backward compatibility (because master will be used as the basis for the next minor revision), and another PR that should go into the next release that can potentially break backward compatibility.

Ah understood. Thanks for your explanation.

@sebastien-rosset
Copy link
Contributor Author

Unrelated network error during build

@sebastien-rosset
Copy link
Contributor Author

Build failure due to unrelated transient network issue.

Copy link
Contributor

@spacether spacether left a comment

Choose a reason for hiding this comment

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

This looks good. Thanks for this PR @sebastien-rosset !

@spacether
Copy link
Contributor

Did we removed a feature where
auth_settings['value'] stored a specific auth data store?

@sebastien-rosset
Copy link
Contributor Author

Did we removed a feature where
auth_settings['value'] stored a specific auth data store?

No, I don't think so. I think the problem is happening because @martyzz1 has a configuration.mustache template based on the old version. In the new configuration.mustache template, the code makes sure to skip auth_settings items if the corresponding auth parameters are not set in the Configuration class.

@sebastien-rosset
Copy link
Contributor Author

Did we removed a feature where
auth_settings['value'] stored a specific auth data store?

Just to make sure, are you referring to @martyzz1's issue, or something else?

@spacether
Copy link
Contributor

Did we removed a feature where
auth_settings['value'] stored a specific auth data store?

Just to make sure, are you referring to @martyzz1's issue, or something else?

I was referring to this PR but upon closer reading of it, I don't think that we removed a feature here. We're okay.

@martyzz1
Copy link

From @sebastien-rosset 's detailed response - and knowing the changes I made to my configuration.mustache - I'd agree that no features are likely to have been removed...

@sebastien-rosset
Copy link
Contributor Author

From @sebastien-rosset 's detailed response - and knowing the changes I made to my configuration.mustache - I'd agree that no features are likely to have been removed...

Thank you for your response. I will mark the issue resolved for now, feel free to reopen if needed.

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.

4 participants