Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove setUserAgent methods from API clients #444

Merged
merged 2 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion V2_MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ We will not provide support and will change these as required without any previo
### Constructors changed

- `AuthenticationAPIClient` can no longer be constructed from a `Context`. Use `AuthenticationAPIClient(auth0: Auth0)` instead. You can create an instance of `Auth0` using a `Context`.
- `UsersAPIClient` can no longer be constructed from a `Context`. Use UsersAPIClient(auth0: Auth0, token: String)` instead. You can create an instance of `Auth0` using a `Context`.
- `UsersAPIClient` can no longer be constructed from a `Context`. Use `UsersAPIClient(auth0: Auth0, token: String)` instead. You can create an instance of `Auth0` using a `Context`.
- `SignupRequest` now requires the second parameter to be an `AuthenticationRequest`.
- `ProfileRequest` now requires an `AuthenticationRequest` and a `Request<UserProfile, AuthenticationException>`.
- `Credentials` can no longer be constructed with an "expires in" value. The date of expiration or "expires at" should be given instead. You typically won't be constructing Credentials on your own.
Expand All @@ -159,6 +159,8 @@ We will not provide support and will change these as required without any previo

#### `AuthenticationAPIClient` methods removed or changed

- `setUserAgent(String)` has been removed. You can set headers to be sent directly on each Request instance using the `addHeader("{NAME}", "{VALUE}")` method or globally to the networking client instance via `DefaultClient(defaultHeaders = mapOf())` constructor parameter.

Methods and classes specific to calling any [Authentication APIs](https://auth0.com/docs/api/authentication) categorized as Legacy have been removed in v2. The following methods have been removed:

- `delegation()`, `delegationWithIdToken("{ID-TOKEN}")`, `delegationWithRefreshToken("{REFRESH-TOKEN}")`, and `delegationWithIdToken("{ID-TOKEN}", "{API-TYPE}}")`. Support for Legacy Authentication API endpoints have been removed.
Expand Down Expand Up @@ -222,6 +224,8 @@ Methods that returned a `TokenRequest` now return a `Request`:

#### `UsersAPIClient` methods changed

- `setUserAgent(String)` has been removed. You can set headers to be sent directly on each Request instance using the `addHeader("{NAME}", "{VALUE}")` method or globally to the networking client instance via `DefaultClient(defaultHeaders = mapOf())` constructor parameter.

Methods that returned a `ParameterizableRequest` now return a `Request`:

- `link("{PRIMARY-USER-ID}", "{SECONDARY-TOKEN}")`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,6 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
public val baseURL: String
get() = auth0.getDomainUrl()

/**
* Set the value of 'User-Agent' header for every request to Auth0 Authentication API
*
* @param userAgent value to send in every request to Auth0
*/
public fun setUserAgent(userAgent: String) {
factory.setUserAgent(userAgent)
}

/**
* Log in a user with email/username and password for a connection/realm.
* It will use the password-realm grant type for the `/oauth/token` endpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,6 @@ public class UsersAPIClient @VisibleForTesting(otherwise = VisibleForTesting.PRI
public val baseURL: String
get() = auth0.getDomainUrl()

/**
* Set the value of 'User-Agent' header for every request to Auth0 Authentication API
*
* @param userAgent value to send in every request to Auth0
*/
public fun setUserAgent(userAgent: String) {
factory.setUserAgent(userAgent)
}

/**
* Link a user identity calling ['/api/v2/users/:primaryUserId/identities'](https://auth0.com/docs/link-accounts#the-management-api) endpoint
* Example usage:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ internal class RequestFactory<U : Auth0Exception> internal constructor(
baseHeaders[AUTH0_CLIENT_INFO_HEADER] = clientInfo
}

fun setUserAgent(userAgent: String) {
baseHeaders[USER_AGENT_HEADER] = userAgent
}

@VisibleForTesting
fun <T> createRequest(
method: HttpMethod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,6 @@ public void shouldUseCustomNetworkingClient() throws IOException {
assertThat(optionsCaptor.getValue().getHeaders(), is(IsMapContaining.hasKey("Auth0-Client")));
}

@Test
public void shouldSetUserAgent() {
Auth0 account = new Auth0("client-id", "https://tenant.auth0.com/");
//noinspection unchecked
RequestFactory<AuthenticationException> factory = mock(RequestFactory.class);
AuthenticationAPIClient client = new AuthenticationAPIClient(account, factory, gson);
client.setUserAgent("nexus-5x");
verify(factory).setUserAgent("nexus-5x");
}

@Test
public void shouldSetAuth0UserAgentIfPresent() {
final Auth0UserAgent auth0UserAgent = mock(Auth0UserAgent.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,6 @@ public void shouldUseCustomNetworkingClient() throws IOException {
assertThat(optionsCaptor.getValue().getHeaders(), is(IsMapContaining.hasKey("Auth0-Client")));
}

@Test
public void shouldSetUserAgent() {
Auth0 account = new Auth0("client-id", "https://tenant.auth0.com/");
//noinspection unchecked
RequestFactory<ManagementException> factory = mock(RequestFactory.class);
final UsersAPIClient client = new UsersAPIClient(account, factory, gson);
client.setUserAgent("android-user-agent");
verify(factory).setUserAgent("android-user-agent");
}

public void shouldSetAuth0UserAgentIfPresent() {
final Auth0UserAgent auth0UserAgent = mock(Auth0UserAgent.class);
when(auth0UserAgent.getValue()).thenReturn("the-user-agent-data");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
public class RequestFactoryTest {

private static final String CLIENT_INFO = "client_info";
private static final String USER_AGENT = "user_agent";
private static final String BASE_URL = "http://domain.auth0.com";

@Mock
Expand Down Expand Up @@ -136,24 +135,6 @@ public void shouldHaveClientInfoHeader() {
verify(patchRequest).addHeader("Auth0-Client", CLIENT_INFO);
}

@Test
public void shouldHaveUserAgentHeader() {
RequestFactory<Auth0Exception> factory = createRequestFactory();
factory.setUserAgent(USER_AGENT);

factory.get(BASE_URL, resultAdapter);
verify(getRequest).addHeader("User-Agent", USER_AGENT);

factory.post(BASE_URL, resultAdapter);
verify(postRequest).addHeader("User-Agent", USER_AGENT);

factory.delete(BASE_URL, resultAdapter);
verify(deleteRequest).addHeader("User-Agent", USER_AGENT);

factory.patch(BASE_URL, resultAdapter);
verify(patchRequest).addHeader("User-Agent", USER_AGENT);
}

@Test
public void shouldCreatePostRequest() {
Request<String, Auth0Exception> request = factory.post(BASE_URL, resultAdapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.fragment.app.Fragment
import com.auth0.android.Auth0
import com.auth0.android.authentication.AuthenticationAPIClient
import com.auth0.android.authentication.AuthenticationException
import com.auth0.android.callback.AuthenticationCallback
import com.auth0.android.callback.Callback
import com.auth0.android.provider.WebAuthProvider
import com.auth0.android.request.DefaultClient
Expand Down Expand Up @@ -51,7 +50,7 @@ class DatabaseLoginFragment : Fragment() {
private fun dbLogin(email: String, password: String) {
apiClient.login(email, password, "Username-Password-Authentication")
//Additional customization to the request goes here
.start(object : AuthenticationCallback<Credentials> {
.start(object : Callback<Credentials, AuthenticationException> {
override fun onFailure(error: AuthenticationException) {
Snackbar.make(requireView(), error.getDescription(), Snackbar.LENGTH_LONG)
.show()
Expand Down