Authentication for Open API generator
Asked Answered
N

1

7

I apologize if this has been answered already, but I can't find a clear answer.

Does the current generator support authentication?

I need to generate a client with 2 potential ways of authentication:

  1. Via API key, which means a required api_token parameter.
  2. Via an OAuth 2 authentication code flow.

If it does, how do I use it?

If it doesn't, what do you think is the best way to add authentication after generating the client?

Neelyneeoma answered 14/3, 2019 at 12:8 Comment(0)
T
1

Given that the OpenAPI Generator can interact with any server that exposes an OpenAPI document, it would follow that one first needs an OpenAPI document that utilizes the security scheme term for authentication and authorization. OpenAPI 3.0 (and 2.0) lets you describe the two desired auth approaches.

Once an OpenAPI document in .yaml or .json format has been created, I believe the Getting Started instructions describe the commands necessary to generate server stubs for authentication, based on the OpenAPI document that you have created for your auth flow.

For example, if your OpenAPI document would happen to be the Swagger Petstore example, you would "generate" thusly:

npx openapi-generator generate -i petstore.yaml -g ruby -o /tmp/test/

Thibodeau answered 15/3, 2019 at 2:47 Comment(2)
We have an outstanding ticket to add a feature matrix (similar to what you'd find on jwt.io, maybe?). Not all generators support all auth types, and the OpenAPI 3.0 security changes are partially implemented. For api_key and oauth, most generators have great support. One complexity to the OP's question… OpenAPI spec states Security Requirement Objects that contain multiple schemes require that all schemes MUST be satisfied for a request to be authorized., meaning multiple schemas aren't either-or as is being asked.Jody
the OP asked for help about the implementation of OAuth 2 at the client side, not at the server.Lands

© 2022 - 2024 — McMap. All rights reserved.