Skip to content

Commit

Permalink
Prepare for release 1.2.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
petersamokhin committed Nov 14, 2023
1 parent e3975fd commit 60e0209
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 29 deletions.
6 changes: 6 additions & 0 deletions auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change log

Version 1.2.0 *(2023-11-14)*
----------------------------

* Support VK custom redirect URL auth with custom tabs
* Bump dependencies

Version 1.1.0 *(2022-12-29)*
----------------------------

Expand Down
9 changes: 7 additions & 2 deletions auth/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ plugins {
}

android {
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

namespace = "com.petersamokhin.vksdk.android.auth"

compileSdk = libs.versions.compileSdk.get().toInt()

defaultConfig {
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.compileSdk.get().toInt()
buildToolsVersion = libs.versions.buildToolsVersion.get()
compileSdk = libs.versions.compileSdk.get().toInt()
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

aarMetadata {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,53 @@ internal object VkResultParser {
@JvmStatic
@CheckResult
fun parseCustomTabs(intent: Intent?): VkAuthResult =
parseCustomTabs(intent?.extras?.toMap())
parseCustomTabs(
dataString = intent?.dataString,
extras = intent?.extras?.toMap()
)

@JvmStatic
@CheckResult
fun parseCustomTabs(extras: Map<String, Any?>?): VkAuthResult {
val referrer = extras?.get(Intent.EXTRA_REFERRER)?.toString()
?: return VkAuthResult.Error(
error = EMPTY_STRING_PARAM,
description = EMPTY_STRING_PARAM,
reason = EMPTY_STRING_PARAM,
exception = VkAuthException("Unknown custom tabs result: $extras")
)
fun parseCustomTabs(dataString: String?, extras: Map<String, Any?>?): VkAuthResult {
val referrerResult: Result<VkAuthResult> = runCatching {
val referrer = extras?.get(Intent.EXTRA_REFERRER)?.toString()
?: return@runCatching VkAuthResult.Error(
error = EMPTY_STRING_PARAM,
description = EMPTY_STRING_PARAM,
reason = EMPTY_STRING_PARAM,
exception = VkAuthException("Unknown custom tabs result: $extras")
)

val uri = Uri.parse(referrer)
val redirectResult = Uri.decode(Uri.decode(uri.getQueryParameter("authorize_url"))) // lol
val uri = Uri.parse(referrer)
val redirectResult = Uri.decode(Uri.decode(uri.getQueryParameter("authorize_url"))) // lol

return parse(Activity.RESULT_OK, mapOf(VkAuthActivity.EXTRA_AUTH_RESULT to redirectResult))
return@runCatching parse(Activity.RESULT_OK, mapOf(VkAuthActivity.EXTRA_AUTH_RESULT to redirectResult))
}

val dataStringResult: Result<VkAuthResult> by lazy(LazyThreadSafetyMode.NONE) {
runCatching {
parse(Activity.RESULT_OK, mapOf(VkAuthActivity.EXTRA_AUTH_RESULT to dataString))
}
}

return when {
referrerResult.isSuccess && referrerResult.getOrThrow() !is VkAuthResult.Error -> {
referrerResult.getOrThrow()
}

dataStringResult.isSuccess && dataStringResult.getOrThrow() !is VkAuthResult.Error -> {
dataStringResult.getOrThrow()
}

else -> {
VkAuthResult.Error(
error = EMPTY_STRING_PARAM,
description = EMPTY_STRING_PARAM,
reason = EMPTY_STRING_PARAM,
exception = VkAuthException("Unknown custom tabs result: $extras")
)
}
}
}

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,27 @@ public class VkResultParserTest {
expectedState
)

assertEquals(expectedResult, VkResultParser.parseCustomTabs(mapOf(Intent.EXTRA_REFERRER to referrer)))
assertEquals(expectedResult, VkResultParser.parseCustomTabs(null, mapOf(Intent.EXTRA_REFERRER to referrer)))
}

@Test
public fun `should parse valid custom tabs result from dataString`() {
val expectedToken = "token1234"
val expectedState = "state1234"
val expectedEmail = "test@example.com"
val expectedExpiresIn = 0
val expectedUserId = 1

val dataString = "https://example.com/redirect#access_token=$expectedToken&expires_in=$expectedExpiresIn&user_id=$expectedUserId&state=$expectedState&email=$expectedEmail"

val expectedResult = VkAuthResult.AccessToken(
expectedToken,
expectedExpiresIn,
expectedUserId,
expectedEmail,
expectedState
)

assertEquals(expectedResult, VkResultParser.parseCustomTabs(dataString, null))
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GROUP=com.petersamokhin.vksdk.android
VERSION_NAME=1.1.0
VERSION_NAME=1.2.0

REPOSITORY_URL_MAVEN_STAGING_DEFAULT=https://oss.sonatype.org/service/local/staging/deploy/maven2/
REPOSITORY_URL_MAVEN_SNAPSHOT_DEFAULT=https://oss.sonatype.org/content/repositories/snapshots/
Expand Down
21 changes: 10 additions & 11 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
[versions]

buildToolsVersion = "33.0.1"
minSdk = "21"
compileSdk = "33"
compileSdk = "34"

kotlin = "1.8.0"
appCompat = "1.5.1"
coreKtx = "1.9.0"
kotlin = "1.9.20"
appCompat = "1.6.1"
coreKtx = "1.12.0"

junit = "4.13.2"
extJunit = "1.1.4"
runner = "1.5.1"
espressoCore = "3.5.0"
extJunit = "1.1.5"
runner = "1.5.2"
espressoCore = "3.5.1"
mockito = "4.9.0"

androidGradle = "7.3.1"
dokka = "1.7.20"
androidGradle = "8.1.3"
dokka = "1.9.10"

browser = "1.4.0"
browser = "1.6.0"
robolectric = "4.9.2"

[libraries]
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Sun Dec 11 21:52:44 MSK 2022
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repo_name: vk-sdk-android
repo_url: https://github.com/vksdk/vk-sdk-android
site_description: "VK SDK Android"
site_author: Peter Samokhin
copyright: 'Copyright &copy; 2022 Peter Samokhin <a href="https://petersamokhin.com">https://petersamokhin.com</a>'
copyright: 'Copyright &copy; 2023 Peter Samokhin <a href="https://petersamokhin.com">https://petersamokhin.com</a>'
remote_branch: gh-pages

nav:
Expand Down

0 comments on commit 60e0209

Please sign in to comment.