Skip to content

Commit

Permalink
Send Java SDK & Target SDK Versions In App2App Auth (#470)
Browse files Browse the repository at this point in the history
* Sending additional information (targetSdk and Java Sdk Versions) to the Dropbox App during authentication.

* Updated documentation.
  • Loading branch information
handstandsam committed Oct 6, 2022
1 parent 4bf2fc2 commit 21ac7e7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,9 @@ public open class AuthActivity : Activity() {

// Create intent to auth with official app.
val officialAuthIntent = DropboxAuthIntent.buildOfficialAuthIntent(
callingActivityFullyQualifiedClassName = this@AuthActivity::class.java.name,
authActivity = this@AuthActivity,
mState = mState,
stateNonce = stateNonce,
packageName = this@AuthActivity.packageName
)

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.dropbox.core.android.internal

import android.content.Context
import android.content.Intent
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import com.dropbox.core.DbxSdkVersion
import com.dropbox.core.android.AuthActivity

internal object DropboxAuthIntent {
Expand All @@ -12,16 +16,29 @@ internal object DropboxAuthIntent {
}
}

fun Context.getTargetSdkVersion(): Int? {
return try {
val packageInfo: PackageInfo = packageManager.getPackageInfo(packageName, 0)
val targetSdkVersion: Int = packageInfo.applicationInfo.targetSdkVersion
targetSdkVersion
} catch (e: Exception) {
null
}
}

/**
* @return Intent to auth with official app
* Extras should be filled in by callee
*/
fun buildOfficialAuthIntent(
mState: AuthSessionViewModel.State,
stateNonce: String,
packageName: String,
callingActivityFullyQualifiedClassName: String
authActivity: AuthActivity,
): Intent {

val callingActivityFullyQualifiedClassName = authActivity::class.java.name
val packageName = authActivity.packageName

return buildActionAuthenticateIntent().apply {
putExtra(EXTRA_CONSUMER_KEY, mState.mAppKey)
putExtra(EXTRA_CONSUMER_SIG, "")
Expand All @@ -31,6 +48,10 @@ internal object DropboxAuthIntent {
putExtra(EXTRA_SESSION_ID, mState.mSessionId)
putExtra(EXTRA_CALLING_PACKAGE, packageName)
putExtra(EXTRA_AUTH_STATE, stateNonce)
putExtra(EXTRA_DROPBOX_SDK_JAVA_VERSION, DbxSdkVersion.Version)
authActivity.getTargetSdkVersion()?.let { targetSdkVersion ->
putExtra(EXTRA_TARGET_SDK_VERSION, targetSdkVersion)
}

mState.mTokenAccessType?.apply {
val queryParams = QueryParamsUtil.createExtraQueryParams(
Expand Down Expand Up @@ -95,6 +116,16 @@ internal object DropboxAuthIntent {
*/
const val EXTRA_AUTH_STATE: String = "AUTH_STATE"

/**
* Used for internal authentication logic. The targetSdk version of the application using the Dropbox SDK Java.
*/
const val EXTRA_TARGET_SDK_VERSION: String = "TARGET_SDK_VERSION"

/**
* Used for internal authentication logic. The version of this Dropbox SDK Java.
*/
const val EXTRA_DROPBOX_SDK_JAVA_VERSION: String = "DROPBOX_SDK_JAVA_VERSION"

/**
* Used for internal authentication. Allows app to request a specific UID to auth against
* You won't ever have to use this.
Expand Down

0 comments on commit 21ac7e7

Please sign in to comment.