Loading app/src/main/java/app/fedilab/android/peertube/activities/LoginActivity.java +15 −21 Original line number Diff line number Diff line Loading @@ -17,18 +17,12 @@ package app.fedilab.android.peertube.activities; import static app.fedilab.android.peertube.client.RetrofitPeertubeAPI.updateCredential; import android.annotation.SuppressLint; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.text.SpannableString; import android.text.Spanned; import android.text.style.ForegroundColorSpan; import android.text.style.UnderlineSpan; import android.util.Patterns; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import android.widget.Toast; import androidx.preference.PreferenceManager; Loading Loading @@ -160,6 +154,7 @@ public class LoginActivity extends BaseBarActivity { oauthParams.setClient_secret(client_secret); oauthParams.setGrant_type("password"); oauthParams.setScope("user"); oauthParams.x_peertube_otp = binding.loginOtp.getText().toString().isEmpty() ? null : binding.loginOtp.getText().toString(); if (binding.loginUid.getText() != null) { oauthParams.setUsername(binding.loginUid.getText().toString().trim()); } Loading @@ -169,24 +164,23 @@ public class LoginActivity extends BaseBarActivity { try { Token token = new RetrofitPeertubeAPI(LoginActivity.this, finalInstance, null).manageToken(oauthParams); proceedLogin(token, finalInstance); } catch (final Exception e) { oauthParams.setUsername(binding.loginUid.getText().toString().toLowerCase().trim()); Token token = null; try { token = new RetrofitPeertubeAPI(LoginActivity.this, finalInstance, null).manageToken(oauthParams); } catch (Error ex) { ex.printStackTrace(); } proceedLogin(token, finalInstance); } catch (Error e) { if (e.getError() != null && e.getError().contains("missing_two_factor")) { runOnUiThread(() -> { binding.loginOtpContainer.setVisibility(View.VISIBLE); binding.loginOtp.setFocusable(true); binding.loginOtp.requestFocus(); binding.loginButton.setEnabled(true); }); } else { runOnUiThread(() -> { Toasty.error(LoginActivity.this, e.getError() != null && !e.getError().isEmpty() ? e.getError() : getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); binding.loginButton.setEnabled(true); }); e.printStackTrace(); } } } @SuppressLint("ApplySharedPref") Loading app/src/main/java/app/fedilab/android/peertube/client/PeertubeService.java +12 −0 Original line number Diff line number Diff line Loading @@ -122,6 +122,18 @@ public interface PeertubeService { @Field("password") String password, @Field("externalAuthToken") String externalAuthToken); @FormUrlEncoded @POST("users/token") Call<Token> otpConnetion( @Header("x-peertube-otp") String externalAuthToken, @Field("client_id") String client_id, @Field("client_secret") String client_secret, @Field("response_type") String response_type, @Field("grant_type") String grant_type, @Field("scope") String scope, @Field("username") String username, @Field("password") String password); //TOKEN //Refresh @FormUrlEncoded Loading app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java +3 −1 Original line number Diff line number Diff line Loading @@ -267,7 +267,9 @@ public class RetrofitPeertubeAPI { public Token manageToken(OauthParams oauthParams) throws Error { PeertubeService peertubeService = init(); Call<Token> refreshTokenCall = null; if (oauthParams.getGrant_type().compareTo("password") == 0) { if (oauthParams.x_peertube_otp != null) { refreshTokenCall = peertubeService.otpConnetion(oauthParams.x_peertube_otp, oauthParams.getClient_id(), oauthParams.getClient_secret(), "code", oauthParams.getGrant_type(), "upload", oauthParams.getUsername(), oauthParams.getPassword()); } else if (oauthParams.getGrant_type().compareTo("password") == 0) { refreshTokenCall = peertubeService.createToken(oauthParams.getClient_id(), oauthParams.getClient_secret(), oauthParams.getGrant_type(), oauthParams.getUsername(), oauthParams.getPassword()); } else if (oauthParams.getGrant_type().compareTo("refresh_token") == 0) { refreshTokenCall = peertubeService.refreshToken(oauthParams.getClient_id(), oauthParams.getClient_secret(), oauthParams.getRefresh_token(), oauthParams.getGrant_type()); Loading app/src/main/java/app/fedilab/android/peertube/client/entities/OauthParams.java +3 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,9 @@ public class OauthParams { private String code; @SerializedName("redirect_uri") private String redirect_uri; @SerializedName("x_peertube_otp") public String x_peertube_otp; public String getClient_secret() { return client_secret; Loading app/src/main/res/layouts/mastodon/values/strings.xml 0 → 100644 +4 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <resources> <string name="otp_message">Two factor authentication token</string> </resources> No newline at end of file Loading
app/src/main/java/app/fedilab/android/peertube/activities/LoginActivity.java +15 −21 Original line number Diff line number Diff line Loading @@ -17,18 +17,12 @@ package app.fedilab.android.peertube.activities; import static app.fedilab.android.peertube.client.RetrofitPeertubeAPI.updateCredential; import android.annotation.SuppressLint; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.text.SpannableString; import android.text.Spanned; import android.text.style.ForegroundColorSpan; import android.text.style.UnderlineSpan; import android.util.Patterns; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import android.widget.Toast; import androidx.preference.PreferenceManager; Loading Loading @@ -160,6 +154,7 @@ public class LoginActivity extends BaseBarActivity { oauthParams.setClient_secret(client_secret); oauthParams.setGrant_type("password"); oauthParams.setScope("user"); oauthParams.x_peertube_otp = binding.loginOtp.getText().toString().isEmpty() ? null : binding.loginOtp.getText().toString(); if (binding.loginUid.getText() != null) { oauthParams.setUsername(binding.loginUid.getText().toString().trim()); } Loading @@ -169,24 +164,23 @@ public class LoginActivity extends BaseBarActivity { try { Token token = new RetrofitPeertubeAPI(LoginActivity.this, finalInstance, null).manageToken(oauthParams); proceedLogin(token, finalInstance); } catch (final Exception e) { oauthParams.setUsername(binding.loginUid.getText().toString().toLowerCase().trim()); Token token = null; try { token = new RetrofitPeertubeAPI(LoginActivity.this, finalInstance, null).manageToken(oauthParams); } catch (Error ex) { ex.printStackTrace(); } proceedLogin(token, finalInstance); } catch (Error e) { if (e.getError() != null && e.getError().contains("missing_two_factor")) { runOnUiThread(() -> { binding.loginOtpContainer.setVisibility(View.VISIBLE); binding.loginOtp.setFocusable(true); binding.loginOtp.requestFocus(); binding.loginButton.setEnabled(true); }); } else { runOnUiThread(() -> { Toasty.error(LoginActivity.this, e.getError() != null && !e.getError().isEmpty() ? e.getError() : getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); binding.loginButton.setEnabled(true); }); e.printStackTrace(); } } } @SuppressLint("ApplySharedPref") Loading
app/src/main/java/app/fedilab/android/peertube/client/PeertubeService.java +12 −0 Original line number Diff line number Diff line Loading @@ -122,6 +122,18 @@ public interface PeertubeService { @Field("password") String password, @Field("externalAuthToken") String externalAuthToken); @FormUrlEncoded @POST("users/token") Call<Token> otpConnetion( @Header("x-peertube-otp") String externalAuthToken, @Field("client_id") String client_id, @Field("client_secret") String client_secret, @Field("response_type") String response_type, @Field("grant_type") String grant_type, @Field("scope") String scope, @Field("username") String username, @Field("password") String password); //TOKEN //Refresh @FormUrlEncoded Loading
app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java +3 −1 Original line number Diff line number Diff line Loading @@ -267,7 +267,9 @@ public class RetrofitPeertubeAPI { public Token manageToken(OauthParams oauthParams) throws Error { PeertubeService peertubeService = init(); Call<Token> refreshTokenCall = null; if (oauthParams.getGrant_type().compareTo("password") == 0) { if (oauthParams.x_peertube_otp != null) { refreshTokenCall = peertubeService.otpConnetion(oauthParams.x_peertube_otp, oauthParams.getClient_id(), oauthParams.getClient_secret(), "code", oauthParams.getGrant_type(), "upload", oauthParams.getUsername(), oauthParams.getPassword()); } else if (oauthParams.getGrant_type().compareTo("password") == 0) { refreshTokenCall = peertubeService.createToken(oauthParams.getClient_id(), oauthParams.getClient_secret(), oauthParams.getGrant_type(), oauthParams.getUsername(), oauthParams.getPassword()); } else if (oauthParams.getGrant_type().compareTo("refresh_token") == 0) { refreshTokenCall = peertubeService.refreshToken(oauthParams.getClient_id(), oauthParams.getClient_secret(), oauthParams.getRefresh_token(), oauthParams.getGrant_type()); Loading
app/src/main/java/app/fedilab/android/peertube/client/entities/OauthParams.java +3 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,9 @@ public class OauthParams { private String code; @SerializedName("redirect_uri") private String redirect_uri; @SerializedName("x_peertube_otp") public String x_peertube_otp; public String getClient_secret() { return client_secret; Loading
app/src/main/res/layouts/mastodon/values/strings.xml 0 → 100644 +4 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <resources> <string name="otp_message">Two factor authentication token</string> </resources> No newline at end of file