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

How to support OAuth2 Password flows? #562

Open
jmg-duarte opened this issue Apr 5, 2024 · 4 comments
Open

How to support OAuth2 Password flows? #562

jmg-duarte opened this issue Apr 5, 2024 · 4 comments
Labels
kind/support Adopter support requests. status/triage Collecting information required to triage the issue.
Milestone

Comments

@jmg-duarte
Copy link

Question

I'm currently developing an API that makes use of OAuth2 Password Flows and need to be able to authenticate to use it.

Currently, there is no OAuth2 specific code, but for my use case, merely allowing me to declare the Authorization header would already solve my issue. However, there is no way (that I know of) of declaring arbitrary headers on the generated code.

I'm already modifying my OpenAPI schema to handle #558 (comment) but would appreciate more escape hatches on the Swift side.

To that end, I am keen on helping implementing the generation for either the escape hatch or the Authorization header on the presence of OAuth security schemes. Just tell me where to look into!

@jmg-duarte jmg-duarte added kind/support Adopter support requests. status/triage Collecting information required to triage the issue. labels Apr 5, 2024
@czechboy0
Copy link
Collaborator

Hi @jmg-duarte,

you're right that there is no special code generated for OAuth2 flows yet, that's a missing feature: https://swiftpackageindex.com/apple/swift-openapi-generator/1.2.1/documentation/swift-openapi-generator/supported-openapi-features#OAuth-Flows-Object

In the short term, we recommend folks implement a ServerMiddleware and add any auth information as a task local, as shown in this example: https://github.com/apple/swift-openapi-generator/tree/main/Examples/auth-server-middleware-example

Long term, it'd be great to see a proposal of how to better support OAuth2 in the generated code. I don't think we've come up with a design yet, and we welcome the community proposing one (using our Proposal process).

@jmg-duarte
Copy link
Author

In the short term, we recommend folks implement a ServerMiddleware and add any auth information as a task local, as shown in this example: https://github.com/apple/swift-openapi-generator/tree/main/Examples/auth-server-middleware-example

I'm doing a client though, would that work?

@czechboy0
Copy link
Collaborator

developing an API

Apologies, I took the above to mean you're writing the server. Yes, just replace ServerMiddleware with ClientMiddleware, and use this example instead: https://github.com/apple/swift-openapi-generator/tree/main/Examples/auth-client-middleware-example

@czechboy0
Copy link
Collaborator

Related to #37.

@czechboy0 czechboy0 added this to the Post-1.0 milestone Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Adopter support requests. status/triage Collecting information required to triage the issue.
Projects
None yet
Development

No branches or pull requests

2 participants