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

Feature/20 vk authorization research #41

Merged
merged 13 commits into from
Feb 9, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/checkPRToDev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
VKIDCLIENTID: ${{ secrets.VKIDCLIENTID }}
VKIDCLIENTSECRET: ${{ secrets.VKIDCLIENTSECRET }}
run: |
./gradlew :app:build

Expand Down
27 changes: 25 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties

import com.google.firebase.appdistribution.gradle.firebaseAppDistribution
import com.android.build.api.dsl.ApplicationDefaultConfig

plugins {
alias(libs.plugins.android.application)
Expand All @@ -25,6 +25,8 @@ android {
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

initVKID()
}

signingConfigs {
Expand All @@ -42,7 +44,7 @@ android {
System.getenv("KEY_PASSWORD") ?: localProperties.getProperty("keyPassword")
?: "keyPasswordEmpty"

storeFile = file("keyStore/cashadvisor.jks" )
storeFile = file("keyStore/cashadvisor.jks")
storePassword = storePasswordLocal
keyAlias = keyAliasLocal
keyPassword = keyPasswordLocal
Expand Down Expand Up @@ -179,6 +181,9 @@ dependencies {
implementation(libs.firebase.analytics)
implementation(platform(libs.firebase.bom))

// Auth vk
implementation(libs.vk.auth)

// Ui Kit Library
implementation(project(":uikit"))

Expand All @@ -188,4 +193,22 @@ dependencies {

kapt {
correctErrorTypes = true
}

fun ApplicationDefaultConfig.initVKID() {
val localProperties = gradleLocalProperties(rootDir)

val clientId = System.getenv("VKIDCLIENTID") ?: localProperties.getProperty("VKIDCLIENTID")
?: throw GradleException("There is no VKIDClientID. Please specify it by ENV.VKIDCLIENTID or VKIDCLIENTID=xxx in local.properties")
val clientSecret =
System.getenv("VKIDCLIENTSECRET") ?: localProperties.getProperty("VKIDCLIENTSECRET")
?: throw GradleException("There is no VKIDClientSecret. Please specify it by ENV.VKIDCLIENTSECRET or VKIDCLIENTSECRET=xxx in local.properties")
addManifestPlaceholders(
mapOf(
"VKIDRedirectHost" to "vk.com",
"VKIDRedirectScheme" to "vk$clientId",
"VKIDClientID" to clientId,
"VKIDClientSecret" to clientSecret
)
)
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:name=".App"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.view.ViewGroup
import androidx.activity.result.ActivityResult
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import app.cashadvisor.R
Expand All @@ -19,13 +20,39 @@ import com.google.android.gms.auth.api.signin.GoogleSignInClient
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.gms.common.api.ApiException
import com.google.android.gms.tasks.Task
import com.vk.id.AccessToken
import com.vk.id.VKID
import com.vk.id.VKIDAuthFail

class EntryFragment : Fragment() {
private var _binding: FragmentEntryBinding? = null
private val binding get() = _binding!!
private lateinit var mGoogleSignInClient: GoogleSignInClient
private lateinit var startResultSignIn: ActivityResultLauncher<Intent>

private val vkAuthCallback = object : VKID.AuthCallback {
override fun onSuccess(accessToken: AccessToken) {
val token = accessToken.token
Toast.makeText(requireContext(), "token: ${token}", Toast.LENGTH_SHORT).show()
Toast.makeText(
requireContext(),
"${accessToken.userData.firstName} ${accessToken.userData.lastName}",
Toast.LENGTH_LONG
).show()
}

override fun onFail(fail: VKIDAuthFail) {
Toast.makeText(requireContext(), "error: ${fail.description}", Toast.LENGTH_LONG).show()
when (fail) {
is VKIDAuthFail.Canceled -> {
//...
}
else -> {
//...
}
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -45,7 +72,6 @@ class EntryFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.btnLogin.setOnClickListener {
findNavController().navigate(R.id.action_entryFragment_to_loginFragment)
}
Expand All @@ -58,6 +84,11 @@ class EntryFragment : Fragment() {
val signIntent = mGoogleSignInClient.signInIntent
startResultSignIn.launch(signIntent)
}
binding.btnAuthVk.setOnClickListener {
val vkid = VKID(requireContext())
vkid.authorize(this, vkAuthCallback)
}

}

override fun onDestroyView() {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/fragment_entry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,14 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintVertical_bias="0.7"/>

<Button
android:id="@+id/btn_auth_vk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/login_via_vk"
android:layout_marginVertical="20dp"
app:layout_constraintStart_toStartOf="@id/btn_signup"
app:layout_constraintTop_toBottomOf="@id/btn_signup" />


</androidx.constraintlayout.widget.ConstraintLayout>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@

<!-- Google authentication-->
<string name="client_id">409936335875-b2f0q0k1rt55vqb3oc751c7121dmd49q.apps.googleusercontent.com</string>
<string name="login_via_vk">Войти через vk</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
12 changes: 12 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven {
url =
java.net.URI("https://artifactory-external.vkpartner.ru/artifactory/vkid-sdk-andorid/")
}
}

versionCatalogs {
Expand Down Expand Up @@ -47,6 +51,8 @@ dependencyResolutionManagement {
version("firebase.appdistribution", "4.0.1")
version("android-library", "8.1.1")
version("gms-play-services-auth", "20.7.0")
version("vkid", "1.0.0")


plugin(
"android-application",
Expand Down Expand Up @@ -297,6 +303,12 @@ dependencyResolutionManagement {
"com.google.android.gms",
"play-services-auth"
).versionRef("gms-play-services-auth")

// Auth vk
library("vk-auth",
"com.vk.id",
"vkid"
).versionRef("vkid")
}
}
}
Expand Down
Loading