use of io.swagger.v3.oas.models.security.OAuthFlow in project flow by vaadin.
the class OpenAPIObjectGenerator method createBasicModel.
private OpenAPI createBasicModel() {
OpenAPI openAPI = new OpenAPI();
Info info = new Info();
info.setTitle(configuration.getApplicationTitle());
info.setVersion(configuration.getApplicationApiVersion());
openAPI.setInfo(info);
Paths paths = new Paths();
openAPI.setPaths(paths);
Server server = new Server();
server.setUrl(configuration.getServerUrl());
server.setDescription(configuration.getServerDescription());
openAPI.setServers(Collections.singletonList(server));
Components components = new Components();
SecurityScheme vaadinConnectOAuth2Scheme = new SecurityScheme().type(SecurityScheme.Type.OAUTH2).flows(new OAuthFlows().password(new OAuthFlow().tokenUrl(VAADIN_CONNECT_OAUTH2_TOKEN_URL).scopes(new Scopes())));
components.addSecuritySchemes(VAADIN_CONNECT_OAUTH2_SECURITY_SCHEME, vaadinConnectOAuth2Scheme);
openAPI.components(components);
return openAPI;
}
use of io.swagger.v3.oas.models.security.OAuthFlow in project swagger-parser by swagger-api.
the class OpenAPIDeserializer method getOAuthFlow.
public OAuthFlow getOAuthFlow(String oAuthFlowType, ObjectNode node, String location, ParseResult result) {
if (node == null) {
return null;
}
OAuthFlow oAuthFlow = new OAuthFlow();
boolean authorizationUrlRequired, tokenUrlRequired, refreshUrlRequired, scopesRequired;
authorizationUrlRequired = tokenUrlRequired = refreshUrlRequired = false;
scopesRequired = true;
switch(oAuthFlowType) {
case "implicit":
authorizationUrlRequired = true;
break;
case "password":
tokenUrlRequired = true;
break;
case "clientCredentials":
tokenUrlRequired = true;
break;
case "authorizationCode":
authorizationUrlRequired = tokenUrlRequired = true;
break;
}
String value = getString("authorizationUrl", node, authorizationUrlRequired, location, result);
if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
oAuthFlow.setAuthorizationUrl(value);
}
value = getString("tokenUrl", node, tokenUrlRequired, location, result);
if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
oAuthFlow.setTokenUrl(value);
}
value = getString("refreshUrl", node, refreshUrlRequired, location, result);
if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
oAuthFlow.setRefreshUrl(value);
}
ObjectNode scopesObject = getObject("scopes", node, scopesRequired, location, result);
Scopes scope = new Scopes();
Set<String> keys = getKeys(scopesObject);
for (String name : keys) {
JsonNode scopeValue = scopesObject.get(name);
if (scopesObject != null) {
scope.addString(name, scopeValue.asText());
}
}
oAuthFlow.setScopes(scope);
Map<String, Object> extensions = getExtensions(node);
if (extensions != null && extensions.size() > 0) {
oAuthFlow.setExtensions(extensions);
}
Set<String> oAuthFlowKeys = getKeys(node);
for (String key : oAuthFlowKeys) {
if (!OAUTHFLOW_KEYS.contains(key) && !key.startsWith("x-")) {
result.extra(location, key, node.get(key));
}
}
return oAuthFlow;
}
Aggregations