diff --git a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java index 32b3374f4..07758956a 100644 --- a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java @@ -39,6 +39,8 @@ import java.util.Map; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; +import retrofit2.Retrofit; +import retrofit2.converter.gson.GsonConverterFactory; public class LoginActivity extends BaseActivity { private static String OAUTH_SCOPES = "read write follow"; @@ -94,6 +96,15 @@ public class LoginActivity extends BaseActivity { startActivity(viewIntent); } + private MastodonAPI getApiFor(String domain) { + Retrofit retrofit = new Retrofit.Builder() + .baseUrl("https://" + domain) + .addConverterFactory(GsonConverterFactory.create()) + .build(); + + return retrofit.create(MastodonAPI.class); + } + /** * Obtain the oauth client credentials for this app. This is only necessary the first time the * app is run on a given server instance. So, after the first authentication, they are @@ -134,9 +145,7 @@ public class LoginActivity extends BaseActivity { } }; - List redirectUris = new ArrayList<>(); - redirectUris.add(getOauthRedirectUri()); - mastodonAPI.authenticateApp(getString(R.string.app_name), redirectUris, OAUTH_SCOPES, + getApiFor(domain).authenticateApp(getString(R.string.app_name), getOauthRedirectUri(), OAUTH_SCOPES, getString(R.string.app_website)).enqueue(callback); } @@ -245,7 +254,7 @@ public class LoginActivity extends BaseActivity { editText.setError(t.getMessage()); } }; - mastodonAPI.fetchOAuthToken(clientId, clientSecret, redirectUri, code, + getApiFor(domain).fetchOAuthToken(clientId, clientSecret, redirectUri, code, "authorization_code").enqueue(callback); } else if (error != null) { /* Authorization failed. Put the error response where the user can read it and they diff --git a/app/src/main/java/com/keylesspalace/tusky/MastodonAPI.java b/app/src/main/java/com/keylesspalace/tusky/MastodonAPI.java index e881f996e..da42829f0 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MastodonAPI.java +++ b/app/src/main/java/com/keylesspalace/tusky/MastodonAPI.java @@ -175,7 +175,7 @@ public interface MastodonAPI { @POST("api/v1/apps") Call authenticateApp( @Field("client_name") String clientName, - @Field("redirect_uris[]") List redirectUris, + @Field("redirect_uris") String redirectUris, @Field("scopes") String scopes, @Field("website") String website);