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.android.authentication.AuthenticationAPIClient.java

License:Open Source License

/**
 * Request a reset password using <a href="https://auth0.com/docs/api/authentication#change-password">'/dbconnections/change_password'</a>
 * Example usage:/*from ww  w  .ja v a  2  s.  c o m*/
 * <pre>
 * {@code
 * client.resetPassword("{email}", "{database connection name}")
 *      .start(new BaseCallback<Void>() {
 *          {@literal}Override
 *          public void onSuccess(Void payload) {}
 *
 *          {@literal}Override
 *          public void onFailure(AuthenticationException error) {}
 *      });
 * }
 * </pre>
 *
 * @param email      of the user to request the password reset. An email will be sent with the reset instructions.
 * @param connection of the database to request the reset password on
 * @return a request to configure and start
 */
@SuppressWarnings("WeakerAccess")
public DatabaseConnectionRequest<Void, AuthenticationException> resetPassword(@NonNull String email,
        @NonNull String connection) {
    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(connection).asDictionary();

    final ParameterizableRequest<Void, AuthenticationException> request = factory
            .POST(url, client, gson, authErrorBuilder).addParameters(parameters);
    return new DatabaseConnectionRequest<>(request);
}

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

License:Open Source License

/**
 * Requests new Credentials using a valid Refresh Token. The received token will have the same audience and scope as first requested. How the new Credentials are requested depends on the {@link Auth0#isOIDCConformant()} flag.
 * - If the instance is OIDC Conformant the endpoint will be /oauth/token with 'refresh_token' grant, and the response will include an id_token and an access_token if 'openid' scope was requested when the refresh_token was obtained.
 * - If the instance is not OIDC Conformant the endpoint will be /delegation with 'urn:ietf:params:oauth:grant-type:jwt-bearer' grant, and the response will include an id_token.
 * Example usage://from  w w  w .j a  va  2s. c  om
 * <pre>
 * {@code
 * client.renewAuth("{refresh_token}")
 *      .addParameter("scope", "openid profile email")
 *      .start(new BaseCallback<Credentials>() {
 *          {@literal}Override
 *          public void onSuccess(Credentials payload) { }
 *
 *          {@literal}@Override
 *          public void onFailure(AuthenticationException error) { }
 *      });
 * }
 * </pre>
 *
 * @param refreshToken used to fetch the new Credentials.
 * @return a request to start
 */
@SuppressWarnings("WeakerAccess")
public ParameterizableRequest<Credentials, AuthenticationException> renewAuth(@NonNull String refreshToken) {
    final Map<String, Object> parameters = ParameterBuilder.newBuilder().setClientId(getClientId())
            .setRefreshToken(refreshToken)
            .setGrantType(auth0.isOIDCConformant() ? ParameterBuilder.GRANT_TYPE_REFRESH_TOKEN
                    : ParameterBuilder.GRANT_TYPE_JWT)
            .asDictionary();

    HttpUrl url;
    if (auth0.isOIDCConformant()) {
        url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder().addPathSegment(OAUTH_PATH)
                .addPathSegment(TOKEN_PATH).build();
    } else {
        url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder().addPathSegment(DELEGATION_PATH).build();
    }

    return factory.POST(url, client, gson, Credentials.class, authErrorBuilder).addParameters(parameters);
}

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

License:Open Source License

/**
 * Performs a custom <a href="https://auth0.com/docs/api/authentication#delegation">delegation</a> request that will
 * yield a delegation token./*  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(AuthenticationException error) {}
 *      });
 * }
 * </pre>
 *
 * @return a request to configure and start
 */
@SuppressWarnings("WeakerAccess")
public ParameterizableRequest<Map<String, Object>, AuthenticationException> 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, gson, authErrorBuilder).addParameters(parameters);
}

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

License:Open Source License

private <T> ParameterizableRequest<T, AuthenticationException> 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, gson, clazz, authErrorBuilder).addParameters(parameters);
}

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

License:Open Source License

/**
 * Start a custom passwordless flow/*w  w  w  .j  a  v  a 2s .c  o m*/
 *
 * @return a request to configure and start
 */
@SuppressWarnings("WeakerAccess")
private ParameterizableRequest<Void, AuthenticationException> 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, gson, authErrorBuilder).addParameters(parameters);
}

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

License:Open Source License

/**
 * Fetch the token information from Auth0, using the authorization_code grant type
 * For Public Client, e.g. Android apps ,you need to provide the code_verifier
 * used to generate the challenge sent to Auth0 {@literal /authorize} method like:
 * <pre>/* w w  w.jav a2 s .  c  om*/
 * {@code
 * AuthenticationAPIClient client = new AuthenticationAPIClient(new Auth0("clientId", "domain"));
 * client
 *     .token("code", "redirect_uri")
 *     .setCodeVerifier("code_verifier")
 *     .start(new Callback<Credentials> {...});
 * }
 * </pre>
 * For the rest of clients, clients who can safely keep a {@literal client_secret}, you need to provide it instead like:
 * <pre>
 * {@code
 * AuthenticationAPIClient client = new AuthenticationAPIClient(new Auth0("clientId", "domain"));
 * client
 *     .token("code", "redirect_uri")
 *     .start(new Callback<Credentials> {...});
 * }
 * </pre>
 *
 * @param authorizationCode the authorization code received from the /authorize call.
 * @param redirectUri       the uri sent to /authorize as the 'redirect_uri'.
 * @return a request to obtain access_token by exchanging a authorization code.
 */
@SuppressWarnings("WeakerAccess")
public TokenRequest token(@NonNull String authorizationCode, @NonNull String redirectUri) {
    Map<String, Object> parameters = ParameterBuilder.newBuilder().setClientId(getClientId())
            .setGrantType(GRANT_TYPE_AUTHORIZATION_CODE).set(OAUTH_CODE_KEY, authorizationCode)
            .set(REDIRECT_URI_KEY, redirectUri).asDictionary();

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

    ParameterizableRequest<Credentials, AuthenticationException> request = factory.POST(url, client, gson,
            Credentials.class, authErrorBuilder);
    request.addParameters(parameters);
    return new TokenRequest(request);
}

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

License:Open Source License

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

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

From source file:com.auth0.android.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())
            .addAll(parameters).asDictionary();
    return factory.authenticationPOST(url, client, gson).addAuthenticationParameters(requestParameters);
}

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

License:Open Source License

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

    return factory.GET(url, client, gson, UserProfile.class, authErrorBuilder);
}

From source file:com.auth0.android.authentication.AuthenticationAPIClientTest.java

License:Open Source License

@Test
public void shouldCreateClientWithAccountInfo() throws Exception {
    AuthenticationAPIClient client = new AuthenticationAPIClient(new Auth0(CLIENT_ID, DOMAIN));
    assertThat(client, is(notNullValue()));
    assertThat(client.getClientId(), equalTo(CLIENT_ID));
    assertThat(HttpUrl.parse(client.getBaseURL()), notNullValue());
    assertThat(HttpUrl.parse(client.getBaseURL()).scheme(), equalTo("https"));
    assertThat(HttpUrl.parse(client.getBaseURL()).host(), equalTo(DOMAIN));
    assertThat(HttpUrl.parse(client.getBaseURL()).pathSize(), is(1));
    assertThat(HttpUrl.parse(client.getBaseURL()).encodedPath(), is("/"));
}