Skip to content

Conversation

@ggpwnkthx
Copy link
Contributor

Using httpx_auth in the glue files so that the httpx authentication parameter is used as much as possible. The changes were designed to handle combination authentication methods. It brings support for OAuth2, AWSSigV4, and more.

Any authentication method in the httpx_auth library can be used directly and dynamically. In order to ensure Security Schemes Objects continue to follow the OpenAPI specifications, the type must be set to "http" and the scheme can be set to any of the httpx_auth classes that extend the httpx.Auth class.

Example Spec:

spec = {...}
spec["components"]["securitySchemes"]["sigv4"] = {"type": "http", "scheme": "aws4auth"}

api = OpenAPI("fict.iv", document=spec)
api.authenticate(
    apiKey="asdf1234",
    sigv4={
        "access_id": "my-access-id",
        "secret_key": "my-secret-key",
        "service": "execute-api",
        "region": "us-east-1",
    },
)

ggpwnkthx added 3 commits June 2, 2023 10:42
Using httpx_auth in the glue files so that the httpx authentication parameter is used as much as possible. The changes were designed to handle combination authentication methods. It brings support for OAuth2, AWSSigV4, and more.

Any authentication method in the httpx_auth library can be used directly and dynamically. In order to ensure Security Schemes Objects continue to follow the OpenAPI specifications, the type must be set to "http" and the scheme can be set to any of the httpx_auth classes that extend the httpx.Auth class.

Example Spec:
spec = {...}
spec["components"]["securitySchemes"]["sigv4"] = {"type": "http", "scheme": "aws4auth"}

api = OpenAPI("fict.iv", document=spec)
api.authenticate(
    apiKey="asdf1234",
    sigv4={
        "access_id": "my-access-id",
        "secret_key": "my-secret-key",
        "service": "execute-api",
        "region": "us-east-1",
    },
)
Added httpx-auth to the install requirements

for auth in add_auths:
if self.req.auth:
self.req.auth += auth
Copy link
Owner

Choose a reason for hiding this comment

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

this actually works?
I guess test_paths_security_combined should validate this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, although conditionally. It's a feature of httpx_auth. Ref: https://github.com/Colin-b/httpx_auth/blob/60bb9a7f4beb4b370398ae8fcb7d4402daa0b0bd/httpx_auth/authentication.py#L93

I think the code should be fine as is since all of that auth objects will be subclasses of httpx_auth.authentication.SupportMultiAuth, however I will add checks for this condition to be safe.

@commonism
Copy link
Owner

Hi,

I'd be more comfortable if httpx-auth was optional and not a hard requirement.
I'll have a look myself and get this merged.
Thanks

Only uses httpx_auth if it's been installed separately.
@ggpwnkthx
Copy link
Contributor Author

That's understandable. In that case, this would probably best be handled by an Authentication plugin of some kind. Although, that may be outside of my development window for the near future.

@commonism
Copy link
Owner

commonism commented Jun 7, 2023

Could you test https://github.com/commonism/aiopenapi3/tree/Esquire-Media/master ?
My changes 81b4f1b

I'll have to document httpx_auth & Colin-b/httpx_auth#48 somehow additionally.

I'd be best if you'd grant me edit privileges for the PR, so I can adjust the PR/repo to incorporate my changes.

@commonism commonism mentioned this pull request Jun 8, 2023
@commonism commonism closed this in #99 Jun 8, 2023
@ggpwnkthx
Copy link
Contributor Author

My apologies, I'm just now seeing your request. Thank you for reviewing, cleaning up, and merging my code. With the issue being close, is there anything you need from me at this point?

@commonism
Copy link
Owner

No - this is settled.
As I intent to migrate master/HEAD to pydanticv2 I created a new release with the feature for use via pip.

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