Search in sources :

Example 16 with OAuthFlow

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;
}
Also used : Components(io.swagger.v3.oas.models.Components) Server(io.swagger.v3.oas.models.servers.Server) OAuthFlows(io.swagger.v3.oas.models.security.OAuthFlows) OAuthFlow(io.swagger.v3.oas.models.security.OAuthFlow) Scopes(io.swagger.v3.oas.models.security.Scopes) Paths(io.swagger.v3.oas.models.Paths) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) SecurityScheme(io.swagger.v3.oas.models.security.SecurityScheme)

Example 17 with OAuthFlow

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) OAuthFlow(io.swagger.v3.oas.models.security.OAuthFlow) Scopes(io.swagger.v3.oas.models.security.Scopes) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

OAuthFlow (io.swagger.v3.oas.models.security.OAuthFlow)15 Scopes (io.swagger.v3.oas.models.security.Scopes)13 SecurityScheme (io.swagger.v3.oas.models.security.SecurityScheme)12 OAuthFlows (io.swagger.v3.oas.models.security.OAuthFlows)10 OpenAPI (io.swagger.v3.oas.models.OpenAPI)8 HashMap (java.util.HashMap)7 LinkedHashMap (java.util.LinkedHashMap)7 Components (io.swagger.v3.oas.models.Components)6 Map (java.util.Map)6 SecurityRequirement (io.swagger.v3.oas.models.security.SecurityRequirement)4 ArrayList (java.util.ArrayList)4 Scope (org.wso2.carbon.apimgt.api.model.Scope)4 Operation (io.swagger.v3.oas.models.Operation)3 PathItem (io.swagger.v3.oas.models.PathItem)3 Info (io.swagger.v3.oas.models.info.Info)3 Server (io.swagger.v3.oas.models.servers.Server)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Contact (io.swagger.v3.oas.models.info.Contact)2 HashSet (java.util.HashSet)2 JSONObject (org.json.simple.JSONObject)2