Merge pull request #1140 from omnivore-app/fix/android-signing

Make the server URL configurable, used shared keys for signing
This commit is contained in:
Satindar Dhillon 2022-08-25 12:56:04 -07:00 committed by GitHub
commit 8b46997b4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 62 additions and 19 deletions

View file

@ -1 +1,3 @@
/build
/build
keystore.properties
*.keystore

View file

@ -6,6 +6,10 @@ plugins {
id 'com.apollographql.apollo3' version '3.5.0'
}
def keystorePropertiesFile = rootProject.file("app/external/keystore.properties");
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
android {
compileSdk 33
@ -13,8 +17,8 @@ android {
applicationId "app.omnivore.omnivore"
minSdk 23
targetSdk 32
versionCode 1
versionName "1.0"
versionCode 2
versionName "0.0.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
@ -22,9 +26,32 @@ android {
}
}
signingConfigs{
release{
keyAlias 'key0'
storeFile file('external/omnivore-prod.keystore')
storePassword keystoreProperties['prodStorePassword']
keyPassword keystoreProperties['prodKeyPassword']
}
debug{
keyAlias 'androiddebugkey'
storeFile file('external/omnivore-demo.keystore')
storePassword keystoreProperties['demoStorePassword']
keyPassword keystoreProperties['demoKeyPassword']
}
}
buildTypes {
debug{
signingConfig signingConfigs.debug
buildConfigField("String", "OMNIVORE_API_URL", "\"https://api-demo.omnivore.app\"")
buildConfigField("String", "OMNIVORE_GAUTH_SERVER_CLIENT_ID", "\"267918240109-eu2ar09unac3lqqigluknhk7t0021b54.apps.googleusercontent.com\"")
}
release {
minifyEnabled false
signingConfig signingConfigs.release
buildConfigField("String", "OMNIVORE_API_URL", "\"https://api-prod.omnivore.app\"")
buildConfigField("String", "OMNIVORE_GAUTH_SERVER_CLIENT_ID", "\"687911924401-lq8j1e97n0sv3khhb8g8n368lk4dqkbp.apps.googleusercontent.com\"")
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

View file

@ -1,7 +1,7 @@
package app.omnivore.omnivore
object Constants {
const val demoProdURL = "https://api-demo.omnivore.app"
const val apiURL = BuildConfig.OMNIVORE_API_URL
const val dataStoreName = "omnivore-datastore"
}

View file

@ -43,7 +43,7 @@ interface AuthProviderLoginSubmit {
object RetrofitHelper {
fun getInstance(): Retrofit {
return Retrofit.Builder().baseUrl(Constants.demoProdURL)
return Retrofit.Builder().baseUrl(Constants.apiURL)
.addConverterFactory(GsonConverterFactory.create())
.build()
}

View file

@ -1,30 +1,27 @@
package app.omnivore.omnivore.ui.auth
import android.app.Activity
import android.content.ContentValues
import android.util.Log
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import app.omnivore.omnivore.BuildConfig
import app.omnivore.omnivore.R
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.gms.common.api.ApiException
import com.google.android.gms.tasks.OnCompleteListener
import com.google.android.gms.tasks.Task
@Composable
fun GoogleAuthButton(viewModel: LoginViewModel) {
val context = LocalContext.current
val signInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(stringResource(R.string.gcp_id))
// .requestServerAuthCode(stringResource(R.string.gcp_id), true)
.requestIdToken(BuildConfig.OMNIVORE_GAUTH_SERVER_CLIENT_ID)
.requestEmail()
.build()
val startForResult =

View file

@ -7,10 +7,8 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.*
import app.omnivore.omnivore.*
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.android.gms.common.api.ApiException
import com.google.android.gms.tasks.OnCompleteListener
import com.google.android.gms.tasks.Task
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.distinctUntilChanged
@ -91,10 +89,10 @@ class LoginViewModel @Inject constructor(
Log.d(ContentValues.TAG, "granted Scopes?: ${result.grantedScopes}")
val googleIdToken = result.idToken
Log.d(ContentValues.TAG, "Google id token?: $googleIdToken")
// TODO: submit id token to backend
// If token is missing then set the error message
// If token is missing then set the error message
if (googleIdToken == null) {
errorMessage = "No authentication token found."
return
}
@ -113,7 +111,7 @@ class LoginViewModel @Inject constructor(
if (result.body()?.authToken != null) {
datastoreRepo.putString(DatastoreKeys.omnivoreAuthToken, result.body()?.authToken!!)
} else {
errorMessage = "Something went wrong. Please check your email/password and try again"
errorMessage = "Something went wrong. Please check your credentials and try again"
}
if (result.body()?.authCookieString != null) {

View file

@ -11,12 +11,17 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import app.omnivore.omnivore.ui.auth.LoginViewModel
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
@Composable
fun HomeView(viewModel: LoginViewModel) {
val context = LocalContext.current
Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
@ -28,6 +33,13 @@ fun HomeView(viewModel: LoginViewModel) {
Text("You have a valid auth token. Nice. Go save something in Chrome!")
Button(onClick = {
// Sign out google users
val signInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.build()
val googleSignIn = GoogleSignIn.getClient(context, signInOptions)
googleSignIn.signOut()
viewModel.logout()
}) {
Text(text = "Logout")

View file

@ -8,7 +8,9 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.material.*
import androidx.compose.material.ButtonDefaults
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import app.omnivore.omnivore.ui.save.SaveViewModel
import kotlinx.coroutines.launch
@ -32,7 +34,12 @@ fun SaveContent(viewModel: SaveViewModel, modalBottomSheetState: ModalBottomShee
coroutineScope.launch {
modalBottomSheetState.hide()
}
}) {
},
colors = ButtonDefaults.buttonColors(
contentColor = Color(0xFF3D3D3D),
backgroundColor = Color(0xffffd234)
)
) {
Text(text = "Dismiss")
}
}

View file

@ -47,7 +47,7 @@ class SaveViewModel @Inject constructor(
}
val apolloClient = ApolloClient.Builder()
.serverUrl("${Constants.demoProdURL}/api/graphql")
.serverUrl("${Constants.apiURL}/api/graphql")
.addHttpHeader("Authorization", value = apiKey)
.build()