Example usage for com.squareup.okhttp HttpUrl parse

List of usage examples for com.squareup.okhttp HttpUrl parse

Introduction

In this page you can find the example usage for com.squareup.okhttp HttpUrl parse.

Prototype

public static HttpUrl parse(String url) 

Source Link

Document

Returns a new HttpUrl representing url if it is a well-formed HTTP or HTTPS URL, or null if it isn't.

Usage

From source file:com.auth0.authentication.AuthenticationAPIClient.java

License:Open Source License

/**
 * Request a change password using <a href="https://auth0.com/docs/auth-api#!#post--dbconnections-change_password">'/dbconnections/change_password'</a>
 * Example usage:/*from w  w  w.  j a  va 2s  . co m*/
 * <pre><code>
 * client.requestChangePassword("{email}")
 *      .start(new BaseCallback<Void>() {
 *          {@literal}Override
 *          public void onSuccess(Void payload) {}
 *
 *          {@literal}Override
 *          public void onFailure(Auth0Exception error) {}
 *      });
 * </code></pre>
 *
 * @param email of the user that changes the password. It's also where the email will be sent with the link to perform the change password.
 * @return a request to configure and start
 */
public DatabaseConnectionRequest<Void> requestChangePassword(String email) {
    HttpUrl url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder().addPathSegment(DB_CONNECTIONS_PATH)
            .addPathSegment(CHANGE_PASSWORD_PATH).build();

    final Map<String, Object> parameters = ParameterBuilder.newBuilder().set(EMAIL_KEY, email)
            .setClientId(getClientId()).setConnection(defaultDatabaseConnection).asDictionary();
    final ParameterizableRequest<Void> request = factory.POST(url, client, mapper).addParameters(parameters);
    return new DatabaseConnectionRequest<>(request);
}

From source file:com.auth0.authentication.AuthenticationAPIClient.java

License:Open Source License

/**
 * Unlink a user identity calling <a href="https://auth0.com/docs/auth-api#!#post--unlink">'/unlink'</a> endpoint
 * Example usage://from  www  .j  a  v  a  2s  . c o  m
 * <pre><code>
 * client.unlink("{auth0 user id}", "{user access token}")
 *      .start(new BaseCallback<Void>() {
 *          {@literal}Override
 *          public void onSuccess(Void payload) {}
 *
 *          {@literal}Override
 *          public void onFailure(Auth0Exception error) {}
 *      });
 * </code></pre>
 *
 * @param userId      of the identity to unlink
 * @param accessToken of the main identity obtained after login
 * @return a request to start
 */
public Request<Void> unlink(String userId, String accessToken) {
    HttpUrl url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder().addPathSegment(UNLINK_PATH).build();

    final Map<String, Object> parameters = ParameterBuilder.newBuilder().setAccessToken(accessToken)
            .set(CLIENT_ID_KEY, getClientId()).set(USER_ID_KEY, userId).asDictionary();

    return factory.POST(url, client, mapper).addParameters(parameters);
}

From source file:com.auth0.authentication.AuthenticationAPIClient.java

License:Open Source License

/**
 * Performs a custom <a href="https://auth0.com/docs/auth-api#!#post--delegation">delegation</a> request that will
 * yield a delegation token./*from w w  w  .  j a v a  2s . c o  m*/
 * Example usage:
 * <pre><code>
 * client.delegation()
 *      .addParameter("api_type", "firebase")
 *      .start(new BaseCallback<Map<String, Object>>() {
 *          {@literal}Override
 *          public void onSuccess(Map<String, Object> payload) {}
 *
 *          {@literal}Override
 *          public void onFailure(Auth0Exception error) {}
 *      });
 * </code></pre>
 *
 * @return a request to configure and start
 */
public ParameterizableRequest<Map<String, Object>> delegation() {
    HttpUrl url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder().addPathSegment(DELEGATION_PATH).build();

    final Map<String, Object> parameters = ParameterBuilder.newBuilder().setClientId(getClientId())
            .setGrantType(ParameterBuilder.GRANT_TYPE_JWT).asDictionary();
    return factory.rawPOST(url, client, mapper).addParameters(parameters);
}

From source file:com.auth0.authentication.AuthenticationAPIClient.java

License:Open Source License

protected <T> ParameterizableRequest<T> delegation(Class<T> clazz) {
    HttpUrl url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder().addPathSegment(DELEGATION_PATH).build();

    final Map<String, Object> parameters = ParameterBuilder.newBuilder().setClientId(getClientId())
            .setGrantType(ParameterBuilder.GRANT_TYPE_JWT).asDictionary();

    return factory.POST(url, client, mapper, clazz).addParameters(parameters);
}

From source file:com.auth0.authentication.AuthenticationAPIClient.java

License:Open Source License

/**
 * Start a custom passwordless flow/*from   w  ww  . ja  va2s .  c  om*/
 *
 * @return a request to configure and start
 */
public ParameterizableRequest<Void> passwordless() {
    HttpUrl url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder().addPathSegment(PASSWORDLESS_PATH)
            .addPathSegment(START_PATH).build();

    final Map<String, Object> parameters = ParameterBuilder.newBuilder().setClientId(getClientId())
            .asDictionary();
    return factory.POST(url, client, mapper).addParameters(parameters);
}

From source file:com.auth0.authentication.AuthenticationAPIClient.java

License:Open Source License

private AuthenticationRequest loginWithResourceOwner(Map<String, Object> parameters) {
    HttpUrl url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder().addPathSegment(OAUTH_PATH)
            .addPathSegment(RESOURCE_OWNER_PATH).build();

    final Map<String, Object> requestParameters = ParameterBuilder.newBuilder().setClientId(getClientId())
            .setConnection(defaultDatabaseConnection).addAll(parameters).asDictionary();
    return factory.authenticationPOST(url, client, mapper).addAuthenticationParameters(requestParameters);
}

From source file:com.auth0.authentication.AuthenticationAPIClient.java

License:Open Source License

private ParameterizableRequest<UserProfile> profileRequest() {
    HttpUrl url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder().addPathSegment(TOKEN_INFO_PATH).build();

    return factory.POST(url, client, mapper, UserProfile.class);
}

From source file:com.auth0.authentication.AuthenticationAPIClient.java

License:Open Source License

/**
 * Fetch the token information from Auth0, using the authorization_code grant type
 *
 * @param authorizationCode the authorization code received from the /authorize call.
 * @param codeVerifier      the code verifier used when requesting a code to /authorize.
 * @param redirectUri       the uri to redirect after a successful request.
 * @return a request to configure and start
 */// ww  w  .j ava 2  s . c  o m
public AuthenticationRequest token(String authorizationCode, String codeVerifier, String redirectUri) {
    Map<String, Object> parameters = ParameterBuilder.newBuilder().setClientId(getClientId())
            .setGrantType(GRANT_TYPE_AUTHORIZATION_CODE).set(OAUTH_CODE_KEY, authorizationCode)
            .set(OAUTH_CODE_VERIFIER_KEY, codeVerifier).set(REDIRECT_URI_KEY, redirectUri).asDictionary();

    HttpUrl url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder().addPathSegment(OAUTH_PATH)
            .addPathSegment(TOKEN_PATH).build();

    return factory.authenticationPOST(url, client, mapper).addAuthenticationParameters(parameters);
}

From source file:com.auth0.request.internal.BaseRequestTest.java

License:Open Source License

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    HttpUrl url = HttpUrl.parse("https://auth0.com");
    baseRequest = new BaseRequest<String>(url, client, reader, errorReader, writer, callback) {
        @Override/*from   ww  w .  j av a  2s.  c  om*/
        public String execute() throws Auth0Exception {
            return null;
        }

        @Override
        public void onResponse(Response response) throws IOException {

        }

        @Override
        protected Request doBuildRequest(Request.Builder builder) throws RequestBodyBuildException {
            return null;
        }
    };
}

From source file:com.google.android.exoplayer.ext.okhttp.OkHttpDataSource.java

License:Apache License

/**
 * Establishes a connection.// w w  w .  j ava  2 s  .  com
 */
private Request makeRequest(DataSpec dataSpec) {
    long position = dataSpec.position;
    long length = dataSpec.length;
    boolean allowGzip = (dataSpec.flags & DataSpec.FLAG_ALLOW_GZIP) != 0;

    HttpUrl url = HttpUrl.parse(dataSpec.uri.toString());
    Request.Builder builder = new Request.Builder().url(url);
    if (cacheControl != null) {
        builder.cacheControl(cacheControl);
    }
    synchronized (requestProperties) {
        for (Map.Entry<String, String> property : requestProperties.entrySet()) {
            builder.addHeader(property.getKey(), property.getValue());
        }
    }
    if (!(position == 0 && length == C.LENGTH_UNBOUNDED)) {
        String rangeRequest = "bytes=" + position + "-";
        if (length != C.LENGTH_UNBOUNDED) {
            rangeRequest += (position + length - 1);
        }
        builder.addHeader("Range", rangeRequest);
    }
    builder.addHeader("User-Agent", userAgent);
    if (!allowGzip) {
        builder.addHeader("Accept-Encoding", "identity");
    }
    if (dataSpec.postBody != null) {
        builder.post(RequestBody.create(null, dataSpec.postBody));
    }
    return builder.build();
}