[access-token] Login with access token
This commit is contained in:
parent
6b15c009ed
commit
e5f2c0c428
|
@ -96,6 +96,12 @@ project.tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
|
||||||
ext.daggerVersion = '2.24'
|
ext.daggerVersion = '2.24'
|
||||||
ext.retrofitVersion = '2.6.0'
|
ext.retrofitVersion = '2.6.0'
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
url 'https://maven.accelf.net/'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if libraries are changed here, they should also be changed in LicenseActivity
|
// if libraries are changed here, they should also be changed in LicenseActivity
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation('com.mikepenz:materialdrawer:6.1.2@aar') {
|
implementation('com.mikepenz:materialdrawer:6.1.2@aar') {
|
||||||
|
@ -165,4 +171,6 @@ dependencies {
|
||||||
|
|
||||||
//Add some useful extensions
|
//Add some useful extensions
|
||||||
implementation 'androidx.core:core-ktx:1.2.0-alpha01'
|
implementation 'androidx.core:core-ktx:1.2.0-alpha01'
|
||||||
|
|
||||||
|
implementation 'net.accelf:easter:1.0.1'
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,6 +173,8 @@
|
||||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
android:resource="@xml/file_paths" />
|
android:resource="@xml/file_paths" />
|
||||||
</provider>
|
</provider>
|
||||||
|
|
||||||
|
<activity android:name="net.accelf.yuito.AccessTokenLoginActivity" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
|
@ -14,6 +14,7 @@ import com.keylesspalace.tusky.di.Injectable
|
||||||
import com.keylesspalace.tusky.util.CustomURLSpan
|
import com.keylesspalace.tusky.util.CustomURLSpan
|
||||||
import kotlinx.android.synthetic.main.activity_about.*
|
import kotlinx.android.synthetic.main.activity_about.*
|
||||||
import kotlinx.android.synthetic.main.toolbar_basic.*
|
import kotlinx.android.synthetic.main.toolbar_basic.*
|
||||||
|
import net.accelf.yuito.AccessTokenLoginActivity
|
||||||
|
|
||||||
class AboutActivity : BottomSheetActivity(), Injectable {
|
class AboutActivity : BottomSheetActivity(), Injectable {
|
||||||
|
|
||||||
|
@ -29,6 +30,10 @@ class AboutActivity : BottomSheetActivity(), Injectable {
|
||||||
|
|
||||||
setTitle(R.string.about_title_activity)
|
setTitle(R.string.about_title_activity)
|
||||||
|
|
||||||
|
easterView.setOnEasterEggExecuteListener {
|
||||||
|
onEasterEggExecute()
|
||||||
|
}
|
||||||
|
|
||||||
versionTextView.text = getString(R.string.about_tusky_version, BuildConfig.VERSION_NAME)
|
versionTextView.text = getString(R.string.about_tusky_version, BuildConfig.VERSION_NAME)
|
||||||
|
|
||||||
aboutLicenseInfoTextView.setClickableTextWithoutUnderlines(R.string.about_tusky_license)
|
aboutLicenseInfoTextView.setClickableTextWithoutUnderlines(R.string.about_tusky_license)
|
||||||
|
@ -46,6 +51,10 @@ class AboutActivity : BottomSheetActivity(), Injectable {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun onEasterEggExecute() {
|
||||||
|
startActivityWithSlideInAnimation(Intent(this, AccessTokenLoginActivity::class.java))
|
||||||
|
}
|
||||||
|
|
||||||
private fun onAccountButtonClick() {
|
private fun onAccountButtonClick() {
|
||||||
viewUrl("https://mastodon.social/@Tusky", getString(R.string.about_tusky_account))
|
viewUrl("https://mastodon.social/@Tusky", getString(R.string.about_tusky_account))
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ class LicenseActivity : BaseActivity() {
|
||||||
setTitle(R.string.title_licenses)
|
setTitle(R.string.title_licenses)
|
||||||
|
|
||||||
loadFileIntoTextView(R.raw.apache, licenseApacheTextView)
|
loadFileIntoTextView(R.raw.apache, licenseApacheTextView)
|
||||||
|
loadFileIntoTextView(R.raw.mit, licenseMitTextView)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import com.keylesspalace.tusky.components.report.ReportActivity
|
||||||
import com.keylesspalace.tusky.components.search.SearchActivity
|
import com.keylesspalace.tusky.components.search.SearchActivity
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.android.ContributesAndroidInjector
|
import dagger.android.ContributesAndroidInjector
|
||||||
|
import net.accelf.yuito.AccessTokenLoginActivity
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by charlag on 3/24/18.
|
* Created by charlag on 3/24/18.
|
||||||
|
@ -97,4 +98,7 @@ abstract class ActivitiesModule {
|
||||||
|
|
||||||
@ContributesAndroidInjector(modules = [FragmentBuildersModule::class])
|
@ContributesAndroidInjector(modules = [FragmentBuildersModule::class])
|
||||||
abstract fun contributesInstanceListActivity(): InstanceListActivity
|
abstract fun contributesInstanceListActivity(): InstanceListActivity
|
||||||
|
|
||||||
|
@ContributesAndroidInjector
|
||||||
|
abstract fun contributesAccessTokenLoginActivity(): AccessTokenLoginActivity
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,110 @@
|
||||||
|
package net.accelf.yuito;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import com.google.android.material.textfield.TextInputEditText;
|
||||||
|
import com.keylesspalace.tusky.MainActivity;
|
||||||
|
import com.keylesspalace.tusky.R;
|
||||||
|
import com.keylesspalace.tusky.db.AccountManager;
|
||||||
|
import com.keylesspalace.tusky.di.Injectable;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import okhttp3.Call;
|
||||||
|
import okhttp3.Callback;
|
||||||
|
import okhttp3.HttpUrl;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
public class AccessTokenLoginActivity extends AppCompatActivity implements Injectable {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
AccountManager accountManager;
|
||||||
|
|
||||||
|
TextInputEditText domainEditText;
|
||||||
|
TextInputEditText accessTokenEditText;
|
||||||
|
TextView logTextView;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_access_token_login);
|
||||||
|
|
||||||
|
domainEditText = findViewById(R.id.domainEditText);
|
||||||
|
accessTokenEditText = findViewById(R.id.accessTokenEditText);
|
||||||
|
Button authorizeButton = findViewById(R.id.authorizeButton);
|
||||||
|
logTextView = findViewById(R.id.logTextView);
|
||||||
|
|
||||||
|
authorizeButton.setOnClickListener(v -> authorize());
|
||||||
|
log("Input domain and access token to login.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void log(String text) {
|
||||||
|
runOnUiThread(() -> logTextView.setText(String.format("%s\n%s", logTextView.getText().toString(), text)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void authorize() {
|
||||||
|
if (domainEditText.getText() != null) {
|
||||||
|
String domain = domainEditText.getText().toString();
|
||||||
|
String accessToken = accessTokenEditText.getText().toString();
|
||||||
|
HttpUrl url;
|
||||||
|
|
||||||
|
log("Starting login test. [domain: " + domain + ", accessToken: " + accessToken + "]");
|
||||||
|
|
||||||
|
try {
|
||||||
|
url = new HttpUrl.Builder().host(domain).scheme("https")
|
||||||
|
.addPathSegments("/api/v1/accounts/verify_credentials")
|
||||||
|
.addQueryParameter("access_token", accessToken)
|
||||||
|
.build();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
log("Wrong domain format. " + e.getMessage());
|
||||||
|
log("Aborting.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log("Access start -> " + url.toString());
|
||||||
|
|
||||||
|
OkHttpClient okHttpClient = new OkHttpClient();
|
||||||
|
Request request = new Request.Builder().url(url).get().build();
|
||||||
|
okHttpClient.newCall(request).enqueue(new Callback() {
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
||||||
|
log("Login failed. " + e.getMessage());
|
||||||
|
log("Aborting.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
|
||||||
|
if (response.body() != null) {
|
||||||
|
log(response.body().string());
|
||||||
|
}
|
||||||
|
if (response.code() != 200) {
|
||||||
|
throw new IOException("Invalid response code. Response code was " + response.code());
|
||||||
|
}
|
||||||
|
log("Login successful. Moving to account registration phase.");
|
||||||
|
authSucceeded(domain, accessToken);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void authSucceeded(String domain, String accessToken) {
|
||||||
|
accountManager.addAccount(accessToken, domain);
|
||||||
|
log("Completed. Enjoy!");
|
||||||
|
|
||||||
|
Intent intent = new Intent(this, MainActivity.class);
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
overridePendingTransition(R.anim.explode, R.anim.explode);
|
||||||
|
}
|
||||||
|
}
|
|
@ -41,6 +41,11 @@
|
||||||
android:textSize="24sp"
|
android:textSize="24sp"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<net.accelf.easter.AccelForceEasterView
|
||||||
|
android:id="@+id/easterView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="60dp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/aboutLicenseInfoTextView"
|
android:id="@+id/aboutLicenseInfoTextView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/domainEditText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ems="10"
|
||||||
|
android:hint="@string/hint_domain"
|
||||||
|
android:inputType="textUri" />
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/accessTokenEditText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/hint_access_token"
|
||||||
|
android:inputType="textNoSuggestions"
|
||||||
|
android:lines="1"
|
||||||
|
tools:ignore="Autofill" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/authorizeButton"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/action_authorize" />
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/logTextView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -202,6 +202,16 @@
|
||||||
license:link="https://github.com/tuskyapp/artwork"
|
license:link="https://github.com/tuskyapp/artwork"
|
||||||
license:name="Tusky elephant artwork" />
|
license:name="Tusky elephant artwork" />
|
||||||
|
|
||||||
|
<com.keylesspalace.tusky.view.LicenseCard
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="12dp"
|
||||||
|
android:layout_marginStart="12dp"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
license:license="@string/license_mit"
|
||||||
|
license:link="https://github.com/accelforce/AccelForceEaster"
|
||||||
|
license:name="AccelForce Easter View" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/licenseApacheTextView"
|
android:id="@+id/licenseApacheTextView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -211,6 +221,15 @@
|
||||||
android:layout_marginTop="12dp"
|
android:layout_marginTop="12dp"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/licenseMitTextView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="18dp"
|
||||||
|
android:layout_marginStart="18dp"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
|
@ -306,6 +306,7 @@
|
||||||
<string name="license_apache_2">Apache Licenseの下にライセンスされています(下記をコピー)</string>
|
<string name="license_apache_2">Apache Licenseの下にライセンスされています(下記をコピー)</string>
|
||||||
<string name="license_cc_by_4">CC-BY 4.0</string>
|
<string name="license_cc_by_4">CC-BY 4.0</string>
|
||||||
<string name="license_cc_by_sa_4">CC-BY-SA 4.0</string>
|
<string name="license_cc_by_sa_4">CC-BY-SA 4.0</string>
|
||||||
|
<string name="license_mit">MIT Licenseの下にライセンスされています (下記にコピー)</string>
|
||||||
<string name="profile_metadata_label">プロフィール メタデータ</string>
|
<string name="profile_metadata_label">プロフィール メタデータ</string>
|
||||||
<string name="profile_metadata_add">データを追加</string>
|
<string name="profile_metadata_add">データを追加</string>
|
||||||
<string name="profile_metadata_label_label">ラベル</string>
|
<string name="profile_metadata_label_label">ラベル</string>
|
||||||
|
|
|
@ -126,6 +126,7 @@
|
||||||
<string name="action_open_reblogged_by">Show boosts</string>
|
<string name="action_open_reblogged_by">Show boosts</string>
|
||||||
<string name="action_open_faved_by">Show favorites</string>
|
<string name="action_open_faved_by">Show favorites</string>
|
||||||
<string name="action_quote">Quote</string>
|
<string name="action_quote">Quote</string>
|
||||||
|
<string name="action_authorize">Authorize Now!</string>
|
||||||
|
|
||||||
<string name="title_hashtags_dialog">Hashtags</string>
|
<string name="title_hashtags_dialog">Hashtags</string>
|
||||||
<string name="title_mentions_dialog">Mentions</string>
|
<string name="title_mentions_dialog">Mentions</string>
|
||||||
|
@ -160,6 +161,7 @@
|
||||||
<string name="hint_search">Search…</string>
|
<string name="hint_search">Search…</string>
|
||||||
<string name="hint_toot_area">Quick Toot Area</string>
|
<string name="hint_toot_area">Quick Toot Area</string>
|
||||||
<string name="hint_default_text">Default Hashtag</string>
|
<string name="hint_default_text">Default Hashtag</string>
|
||||||
|
<string name="hint_access_token">Access Token</string>
|
||||||
|
|
||||||
<string name="search_no_results">No results</string>
|
<string name="search_no_results">No results</string>
|
||||||
|
|
||||||
|
@ -404,6 +406,7 @@
|
||||||
<string name="license_apache_2">Licensed under the Apache License (copy below)</string>
|
<string name="license_apache_2">Licensed under the Apache License (copy below)</string>
|
||||||
<string name="license_cc_by_4">CC-BY 4.0</string>
|
<string name="license_cc_by_4">CC-BY 4.0</string>
|
||||||
<string name="license_cc_by_sa_4">CC-BY-SA 4.0</string>
|
<string name="license_cc_by_sa_4">CC-BY-SA 4.0</string>
|
||||||
|
<string name="license_mit">Licensed under the MIT License (copy below)</string>
|
||||||
|
|
||||||
<string name="profile_metadata_label">Profile metadata</string>
|
<string name="profile_metadata_label">Profile metadata</string>
|
||||||
<string name="profile_metadata_add">add data</string>
|
<string name="profile_metadata_add">add data</string>
|
||||||
|
|
Loading…
Reference in New Issue