Java Code Examples for io.vertx.ext.auth.oauth2.OAuth2FlowType#AUTH_CODE

The following examples show how to use io.vertx.ext.auth.oauth2.OAuth2FlowType#AUTH_CODE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OAuth2API.java    From vertx-auth with Apache License 2.0 6 votes vote down vote up
/**
 * The client sends the end-user's browser to this endpoint to request their authentication and consent. This endpoint is used in the code and implicit OAuth 2.0 flows which require end-user interaction.
 *
 * see: https://tools.ietf.org/html/rfc6749
 */
public String authorizeURL(JsonObject params) {
  final JsonObject query = params.copy();

  if (config.getFlow() != OAuth2FlowType.AUTH_CODE) {
    throw new IllegalStateException("authorization URL cannot be computed for non AUTH_CODE flow");
  }

  if (query.containsKey("scopes")) {
    // scopes have been passed as a list so the provider must generate the correct string for it
    query.put("scope", String.join(config.getScopeSeparator(), query.getJsonArray("scopes").getList()));
    query.remove("scopes");
  }

  query.put("response_type", "code");
  query.put("client_id", config.getClientID());

  final String path = config.getAuthorizationPath();
  final String url = path.charAt(0) == '/' ? config.getSite() + path : path;

  return url + '?' + stringify(query);
}
 
Example 2
Source File: KeycloakOAuthFactory.java    From apiman with Apache License 2.0 5 votes vote down vote up
public static AuthHandler create(Vertx vertx, Router router, VertxEngineConfig apimanConfig, JsonObject authConfig) {
    OAuth2FlowType flowType = toEnum(authConfig.getString("flowType"));
    String role = authConfig.getString("requiredRole");

    Objects.requireNonNull(flowType, String.format("flowType must be specified and valid. Flows: %s.", Arrays.asList(OAuth2FlowType.values())));
    Objects.requireNonNull(role, "requiredRole must be non-null.");

    if (flowType != OAuth2FlowType.AUTH_CODE) {
        return directGrant(vertx, apimanConfig, authConfig, flowType, role);
    } else {
        return standardAuth(vertx, router, apimanConfig, authConfig, flowType);
    }
}
 
Example 3
Source File: AbstractOAuth2Base.java    From apiman with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("nls")
protected OAuth2FlowType getFlowType(String flowAsString) {
    switch(flowAsString.toUpperCase()) {
    case "AUTH_CODE":
    case "AUTHCODE":
        return OAuth2FlowType.AUTH_CODE;
    case "CLIENT":
        return OAuth2FlowType.CLIENT;
    case "PASSWORD":
        return OAuth2FlowType.PASSWORD;
    }
    throw new OAuth2Exception("Unrecognised OAuth2FlowType " + flowAsString);
}