11package io .quarkiverse .openapi .generator ;
22
3- import java .util .Map ;
43import java .util .Optional ;
54
6- import io .quarkiverse .openapi .generator .providers .ApiKeyAuthenticationProvider ;
7- import io .quarkiverse .openapi .generator .providers .BasicAuthenticationProvider ;
8- import io .quarkiverse .openapi .generator .providers .BearerAuthenticationProvider ;
95import io .quarkus .runtime .annotations .ConfigGroup ;
10- import io .quarkus .runtime .annotations .ConfigItem ;
116
127/**
138 * This class represents the runtime authentication related configuration for an individual securityScheme present
149 * on an OpenApi spec definition, i.e. the provided files.
1510 */
1611@ ConfigGroup
17- public class AuthConfig {
12+ public interface AuthConfig {
1813
19- public static final String TOKEN_PROPAGATION = "token-propagation" ;
20- public static final String HEADER_NAME = "header-name" ;
14+ String TOKEN_PROPAGATION = "token-propagation" ;
15+ String HEADER_NAME = "header-name" ;
2116
2217 /**
2318 * Enables the authentication token propagation for this particular securityScheme.
@@ -31,8 +26,7 @@ public class AuthConfig {
3126 * @see SpecItemConfig
3227 * @see OpenApiGeneratorConfig
3328 */
34- @ ConfigItem (defaultValue = "false" )
35- public Optional <Boolean > tokenPropagation ;
29+ Optional <Boolean > tokenPropagation ();
3630
3731 /**
3832 * Configures a particular http header attribute from were to take the security token from when the token propagation
@@ -47,48 +41,91 @@ public class AuthConfig {
4741 * @see SpecItemConfig
4842 * @see OpenApiGeneratorConfig
4943 */
50- @ ConfigItem
51- public Optional <String > headerName ;
44+ Optional <String > headerName ();
5245
5346 /**
54- * Configures a particular parameter value to be used by any of the different internal authentication filters
55- * that processes the different securityScheme definitions.
56- * <p>
47+ * Sets the Basic Authentication username for a given OpenAPI securityScheme.
48+ * <p/>
5749 * For example, given a file named petstore.json with a securityScheme named "petstore-basic-auth", that is of
58- * http basic authentication type, the following configuration can establish the user and password to be used.
59- * must be used.
60- * <p>
50+ * http basic authentication type, the following configuration can establish the user to be used.
51+ * <p/>
6152 * quarkus.openapi-generator.petstore_json.auth.petstore_basic_auth.username=MyUserName
62- * quarkus.openapi-generator.petstore_json.auth.petstore_basic_auth.password=MyPassword
6353 *
64- * @see AuthsConfig
65- * @see SpecItemConfig
66- * @see OpenApiGeneratorConfig
67- * @see BasicAuthenticationProvider
68- * @see BearerAuthenticationProvider
69- * @see ApiKeyAuthenticationProvider
54+ * @return the username portion for Basic Authentication
55+ * @see AuthConfig#password()
56+ * @see <a href="https://spec.openapis.org/oas/v3.1.0.html#basic-authentication-sample">4.8.27.2.1 Basic Authentication
57+ * Sample</a>
7058 */
71- @ ConfigItem (name = ConfigItem .PARENT )
72- public Map <String , String > authConfigParams ;
59+ Optional <String > username ();
7360
74- public Optional <Boolean > getTokenPropagation () {
75- return tokenPropagation ;
76- }
61+ /**
62+ * Sets the Basic Authentication password for a given OpenAPI securityScheme.
63+ * <p/>
64+ * For example, given a file named petstore.json with a securityScheme named "petstore-basic-auth", that is of
65+ * http basic authentication type, the following configuration can establish the password to be used.
66+ * <p/>
67+ * quarkus.openapi-generator.petstore_json.auth.petstore_basic_auth.password=MyPassword
68+ * <p/>
69+ * Ignored if the given securityScheme is not Basic Authentication
70+ *
71+ * @return the password portion for Basic Authentication
72+ * @see AuthConfig#username()
73+ * @see <a href="https://spec.openapis.org/oas/v3.1.0.html#basic-authentication-sample">4.8.27.2.1 Basic Authentication
74+ * Sample</a>
75+ */
76+ Optional <String > password ();
7777
78- public Optional <String > getHeaderName () {
79- return headerName ;
80- }
78+ /**
79+ * Sets the Bearer Token for a given OpenAPI securityScheme.
80+ * <p/>
81+ * For example, given a file named petstore.json with a securityScheme named "petstore-bearer-auth", that is of
82+ * bearer authentication type, the following configuration can establish the token to be used.
83+ * <p/>
84+ * quarkus.openapi-generator.petstore_json.auth.petstore_bearer_auth.token=1234567890
85+ * <p/>
86+ * Ignored if the given securityScheme is not Bearer Token Authentication
87+ *
88+ * @return the token
89+ * @see <a href="https://spec.openapis.org/oas/v3.1.0.html#jwt-bearer-sample">4.8.27.2.3 JWT Bearer Sample</a>
90+ */
91+ Optional <String > bearerToken ();
8192
82- public Optional <String > getConfigParam (String paramName ) {
83- return Optional .ofNullable (authConfigParams .get (paramName ));
84- }
93+ /**
94+ * Sets the API Key for a given OpenAPI securityScheme.
95+ * <p/>
96+ * For example, given a file named petstore.json with a securityScheme named "petstore-apikey-auth", that is of
97+ * API Key authentication type, the following configuration can establish the API Key to be used.
98+ * <p/>
99+ * quarkus.openapi-generator.petstore_json.auth.petstore_apikey_auth.api-key=${MY_SECRET_KEY_IN_AN_ENV_VAR}
100+ * <p/>
101+ * Ignored if the given securityScheme is not API Key Authentication
102+ *
103+ * @return the token
104+ * @see <a href="https://spec.openapis.org/oas/v3.1.0.html#api-key-sample">4.8.27.2.2 API Key Samplee</a>
105+ */
106+ Optional <String > apiKey ();
85107
86- @ Override
87- public String toString () {
88- return "AuthConfig{" +
89- "tokenPropagation=" + tokenPropagation +
90- ", headerName=" + headerName +
91- ", authConfigParams=" + authConfigParams +
92- '}' ;
93- }
108+ /**
109+ * Only valid for API Key Authentication.
110+ * <p/>
111+ * When to add the `Authorization` value to the API Key in the authentication header.
112+ * <p/>
113+ * For example, if this property is set to `true`, the API Key will be sent to the server in the header along with
114+ * `Authorization`:
115+ * <p/>
116+ * [source]
117+ * ---
118+ * Authentication: Authorization MY-API-KEY
119+ * ---
120+ * <p/>
121+ * If set to `false`, the header should be:
122+ * <p/>
123+ * [source]
124+ * ---
125+ * Authentication: MY-API-KEY
126+ * ---
127+ *
128+ * @return whether to use the prefix `Authorization` when sending an API Key using headers.
129+ */
130+ Optional <Boolean > useAuthorizationHeaderValue ();
94131}
0 commit comments