org.openapitools.client.auth.Authentication Java Examples

The following examples show how to use org.openapitools.client.auth.Authentication. 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: ApiClient.java    From openapi-generator with Apache License 2.0 7 votes vote down vote up
protected void init() {
    // Use RFC3339 format for date and datetime.
    // See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14
    this.dateFormat = new RFC3339DateFormat();

    // Use UTC as the default time zone.
    this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

    // Set default User-Agent.
    setUserAgent("Java-SDK");

    // Setup authentications (key: authentication name, value: authentication).
    authentications = new HashMap<String, Authentication>();
    authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
    authentications.put("api_key_query", new ApiKeyAuth("query", "api_key_query"));
    authentications.put("http_basic_test", new HttpBasicAuth());
    authentications.put("petstore_auth", new OAuth());
    // Prevent the authentications from being modified.
    authentications = Collections.unmodifiableMap(authentications);
}
 
Example #2
Source File: ApiInvoker.java    From swaggy-jenkins with MIT License 5 votes vote down vote up
/**
 * Helper method to set API key value for the first API key authentication.
 */
public void setApiKey(String apiKey) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof ApiKeyAuth) {
      ((ApiKeyAuth) auth).setApiKey(apiKey);
      return;
    }
  }
  throw new RuntimeException("No API key authentication configured!");
}
 
Example #3
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set API key prefix for the first API key authentication.
 * @param apiKeyPrefix the API key prefix
 */
public void setApiKeyPrefix(String apiKeyPrefix) {
    for (Authentication auth : authentications.values()) {
        if (auth instanceof ApiKeyAuth) {
            ((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix);
            return;
        }
    }
    throw new RuntimeException("No API key authentication configured!");
}
 
Example #4
Source File: ApiInvoker.java    From swagger-aem with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set username for the first HTTP basic authentication.
 */
public void setUsername(String username) {
  for (Authentication auth : authentications.values()) {
     if (auth instanceof HttpBasicAuth) {
         ((HttpBasicAuth) auth).setUsername(username);
         return;
     }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #5
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set API key value for the first API key authentication.
 *
 * @param apiKey API key
 */
public void setApiKey(String apiKey) {
    for (Authentication auth : authentications.values()) {
        if (auth instanceof ApiKeyAuth) {
            ((ApiKeyAuth) auth).setApiKey(apiKey);
            return;
        }
    }
    throw new RuntimeException("No API key authentication configured!");
}
 
Example #6
Source File: ApiInvoker.java    From swagger-aem with Apache License 2.0 5 votes vote down vote up
/**
 * Update query and header parameters based on authentication settings.
 *
 * @param authNames The authentications to apply
 */
private void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams) {
  for (String authName : authNames) {
    Authentication auth = authentications.get(authName);
    if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);
      auth.applyToParams(queryParams, headerParams);
  }
}
 
Example #7
Source File: ApiInvoker.java    From swaggy-jenkins with MIT License 5 votes vote down vote up
public static void initializeInstance(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery, int connectionTimeout) {
  INSTANCE = new ApiInvoker(cache, network, threadPoolSize, delivery, connectionTimeout);
  setUserAgent("OpenAPI-Generator/1.0.0/android");

  // Setup authentications (key: authentication name, value: authentication).
  INSTANCE.authentications = new HashMap<String, Authentication>();
  INSTANCE.authentications.put("jenkins_auth", new HttpBasicAuth());
  INSTANCE.authentications.put("jwt_auth", new ApiKeyAuth("header", "Authorization"));
  // Prevent the authentications from being modified.
  INSTANCE.authentications = Collections.unmodifiableMap(INSTANCE.authentications);
}
 
Example #8
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to configure the token endpoint of the first oauth found in the apiAuthorizations (there should be only one)
 *
 * @return Token request builder
 */
public TokenRequestBuilder getTokenEndPoint() {
    for (Authentication apiAuth : authentications.values()) {
        if (apiAuth instanceof RetryingOAuth) {
            RetryingOAuth retryingOAuth = (RetryingOAuth) apiAuth;
            return retryingOAuth.getTokenRequestBuilder();
        }
    }
    return null;
}
 
Example #9
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set API key value for the first API key authentication.
 * @param apiKey the API key
 */
public void setApiKey(String apiKey) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof ApiKeyAuth) {
      ((ApiKeyAuth) auth).setApiKey(apiKey);
      return;
    }
  }
  throw new RuntimeException("No API key authentication configured!");
}
 
Example #10
Source File: ApiInvoker.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Update query and header parameters based on authentication settings.
 *
 * @param authNames The authentications to apply
 */
private void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams) {
  for (String authName : authNames) {
    Authentication auth = authentications.get(authName);
    if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);
      auth.applyToParams(queryParams, headerParams);
  }
}
 
Example #11
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set username for the first HTTP basic authentication.
 * @param username Username
 */
public void setUsername(String username) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof HttpBasicAuth) {
      ((HttpBasicAuth) auth).setUsername(username);
      return;
    }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #12
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set password for the first HTTP basic authentication.
 * @param password Password
 */
public void setPassword(String password) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof HttpBasicAuth) {
      ((HttpBasicAuth) auth).setPassword(password);
      return;
    }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #13
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set username for the first HTTP basic authentication.
 * @param username Username
 */
public void setUsername(String username) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof HttpBasicAuth) {
      ((HttpBasicAuth) auth).setUsername(username);
      return;
    }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #14
Source File: ApiInvoker.java    From swaggy-jenkins with MIT License 5 votes vote down vote up
/**
 * Helper method to set password for the first HTTP basic authentication.
 */
public void setPassword(String password) {
  for (Authentication auth : authentications.values()) {
     if (auth instanceof HttpBasicAuth) {
        ((HttpBasicAuth) auth).setPassword(password);
        return;
     }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #15
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Update query and header parameters based on authentication settings.
 *
 * @param authNames The authentications to apply
 */
protected void updateParamsForAuth(String[] authNames, List<Pair> queryParams, MultiMap headerParams, MultiMap cookieParams) {
    for (String authName : authNames) {
        Authentication auth = authentications.get(authName);
        if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);
        auth.applyToParams(queryParams, headerParams, cookieParams);
    }
}
 
Example #16
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set access token for the first OAuth2 authentication.
 *
 * @param accessToken Access token
 */
public ApiClient setAccessToken(String accessToken) {
    for (Authentication auth : authentications.values()) {
        if (auth instanceof OAuth) {
            ((OAuth) auth).setAccessToken(accessToken);
            return this;
        }
    }
    throw new RuntimeException("No OAuth2 authentication configured!");
}
 
Example #17
Source File: ApiInvoker.java    From swagger-aem with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set API key prefix for the first API key authentication.
 */
public void setApiKeyPrefix(String apiKeyPrefix) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof ApiKeyAuth) {
      ((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix);
      return;
    }
  }
  throw new RuntimeException("No API key authentication configured!");
}
 
Example #18
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set API key value for the first API key authentication.
 *
 * @param apiKey API key
 */
public ApiClient setApiKey(String apiKey) {
    for (Authentication auth : authentications.values()) {
        if (auth instanceof ApiKeyAuth) {
            ((ApiKeyAuth) auth).setApiKey(apiKey);
            return this;
        }
    }
    throw new RuntimeException("No API key authentication configured!");
}
 
Example #19
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set password for the first HTTP basic authentication.
 *
 * @param password Password
 */
public ApiClient setPassword(String password) {
    for (Authentication auth : authentications.values()) {
        if (auth instanceof HttpBasicAuth) {
            ((HttpBasicAuth) auth).setPassword(password);
            return this;
        }
    }
    throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #20
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set API key prefix for the first API key authentication.
 *
 * @param apiKeyPrefix API key prefix
 */
public void setApiKeyPrefix(String apiKeyPrefix) {
    for (Authentication auth : authentications.values()) {
        if (auth instanceof ApiKeyAuth) {
            ((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix);
            return;
        }
    }
    throw new RuntimeException("No API key authentication configured!");
}
 
Example #21
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set access token for the first Bearer authentication.
 * @param bearerToken Bearer token
 */
public ApiClient setBearerToken(String bearerToken) {
    for (Authentication auth : authentications.values()) {
        if (auth instanceof HttpBearerAuth) {
            ((HttpBearerAuth) auth).setBearerToken(bearerToken);
            return this;
        }
    }
    throw new RuntimeException("No Bearer authentication configured!");
}
 
Example #22
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set access token for the first OAuth2 authentication.
 * @param accessToken Access token
 */
public void setAccessToken(String accessToken) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof OAuth) {
      ((OAuth) auth).setAccessToken(accessToken);
      return;
    }
  }
  throw new RuntimeException("No OAuth2 authentication configured!");
}
 
Example #23
Source File: ApiInvoker.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set API key value for the first API key authentication.
 */
public void setApiKey(String apiKey) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof ApiKeyAuth) {
      ((ApiKeyAuth) auth).setApiKey(apiKey);
      return;
    }
  }
  throw new RuntimeException("No API key authentication configured!");
}
 
Example #24
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Update query and header parameters based on authentication settings.
 *
 * @param authNames The authentications to apply
 * @param queryParams List of query parameters
 * @param headerParams Map of header parameters
 * @param cookieParams Map of cookie parameters
 * @param method HTTP method (e.g. POST)
 * @param uri HTTP URI
 */
protected void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams,
                                   Map<String, String> cookieParams, String payload, String method, URI uri) throws ApiException {
  for (String authName : authNames) {
    Authentication auth = authentications.get(authName);
    if (auth == null) {
      continue;
    }
    auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri);
  }
}
 
Example #25
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set the scopes for the first OAuth2 authentication.
 *
 * @param scope the oauth scope
 */
public ApiClient setOauthScope(String scope) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof OAuth) {
      ((OAuth) auth).setScope(scope);
      return this;
    }
  }
  throw new RuntimeException("No OAuth2 authentication configured!");
}
 
Example #26
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set the authorization code flow for the first OAuth2 authentication.
 *
 * @param code the authorization code
 */
public ApiClient setOauthAuthorizationCodeFlow(String code) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof OAuth) {
      ((OAuth) auth).useAuthorizationCodeFlow(code);
      return this;
    }
  }
  throw new RuntimeException("No OAuth2 authentication configured!");
}
 
Example #27
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set the password flow for the first OAuth2 authentication.
 *
 * @param username the user name
 * @param password the user password
 */
public ApiClient setOauthPasswordFlow(String username, String password) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof OAuth) {
      ((OAuth) auth).usePasswordFlow(username, password);
      return this;
    }
  }
  throw new RuntimeException("No OAuth2 authentication configured!");
}
 
Example #28
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set the credentials for the first OAuth2 authentication.
 *
 * @param clientId the client ID
 * @param clientSecret the client secret
 */
public ApiClient setOauthCredentials(String clientId, String clientSecret) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof OAuth) {
      ((OAuth) auth).setCredentials(clientId, clientSecret, isDebugging());
      return this;
    }
  }
  throw new RuntimeException("No OAuth2 authentication configured!");
}
 
Example #29
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set bearer token for the first Bearer authentication.
 *
 * @param bearerToken Bearer token
 */
public ApiClient setBearerToken(String bearerToken) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof HttpBearerAuth) {
      ((HttpBearerAuth) auth).setBearerToken(bearerToken);
      return this;
    }
  }
  throw new RuntimeException("No Bearer authentication configured!");
}
 
Example #30
Source File: ApiInvoker.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set password for the first HTTP basic authentication.
 */
public void setPassword(String password) {
  for (Authentication auth : authentications.values()) {
     if (auth instanceof HttpBasicAuth) {
        ((HttpBasicAuth) auth).setPassword(password);
        return;
     }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}