我正在使用 appAuth-android 登录我的应用程序,并且我想传递一个自定义标头。为了允许自定义标头,我已经完成了数字资产链接建议的所有操作。
数字资产链接码
private var session: CustomTabsSession? = null
private var customTabsIntent: CustomTabsIntent? = null
private var callback: CustomTabsCallback = object : CustomTabsCallback() {
override fun onRelationshipValidationResult(
relation: Int,
requestedOrigin: Uri,
result: Boolean,
extras: Bundle?
) {
customTabsIntent = CustomTabsIntent.Builder(session).build().apply {
this.intent.putExtra(
Browser.EXTRA_HEADERS,
Bundle().apply {
putString(
HEADER,
DATA
)
}
)
}
}
}
private val connection: CustomTabsServiceConnection = object : CustomTabsServiceConnection() {
override fun onCustomTabsServiceConnected(
name: ComponentName,
client: CustomTabsClient
) {
session = client.newSession(callback)
client.warmup(0)
val validated = session?.validateRelationship(
CustomTabsService.RELATION_HANDLE_ALL_URLS,
Uri.parse(SERVER_URL), null
)
Log.i("customTabs", "connection: isValidated = $validated")
}
override fun onServiceDisconnected(componentName: ComponentName) {}
}
override fun onStart() {
super.onStart()
CustomTabsClient.bindCustomTabsService(
this,
CustomTabsClient.getPackageName(
this,
getCustomTabsPackages().map {
it.activityInfo.packageName
}
),
connection
)
当我运行代码时,日志会返回,因为它已经过验证
使用 customTab 授权
val configuration =authConfig(webPage)
val redirectUri = REDIRECT_URI
val request = AuthorizationRequest.Builder(
configuration, CLIENT_ID, CODE, redirectUri
).build()
try {
val postAuthorizationIntent = Intent(context, Activity::class.java).apply {
action = ACTION_AUTHORIZATION
}
val pendingIntent = PendingIntent.getActivity(context, 0, postAuthorizationIntent, 0)
authService.performAuthorizationRequest(request, pendingIntent, customTabsIntent ?: backupTabIntent)
授权工作正常,只是我的自定义标题没有出现