【问题标题】:Android AppAuth - following the PendingIntent objectAndroid AppAuth - 遵循 PendingIntent 对象
【发布时间】:2019-08-28 13:34:20
【问题描述】:

我一直在尝试在 Android 中实现 Google 的 AppAuth 库,但我很难让它发挥作用。我一直在尝试遵循 guide from Google 并将其应用于我自己的代码库,但我被待定的意图所困扰。

更具体地说,当我调用performAuthorizationRequest() 方法时,模拟器可以按照重定向在其自定义选项卡中获取验证码(我可以看到它)。但是,没有调用任何处理程序。我尝试添加 onNewIntent()onActivityResult()onResume(),但没有一个被调用。

performAuthorizationRequest() 的 Javadocs 中,我看到了

"提供的 {@link PendingIntent 完成 PendingIntent} 将是 调用”。

这是什么意思?如何与已完成的 pendingIntent 对象进行交互?有没有什么方法可以在创建挂起意图时使用发送的请求代码检索该上下文?

下面是我的代码:

var authReq: AuthorizationRequest = AuthorizationRequest.Builder(
            serverConfig,
            clientId,
            ResponseTypeValues.CODE,
            redirectUri
).build()

val service: AuthorizationService = AuthorizationService(view.context)

val action = "com.google.codelabs.appauth.HANDLE_AUTHORIZATION_RESPONSE"
val authIntent = Intent(action)
val pendingIntent = PendingIntent.getActivity(this, authReq.hashCode(), authIntent, 0)

service.performAuthorizationRequest(authReq, pendingIntent)

在我的清单中,我添加了活动:

<activity android:name=".MainActivity" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

    <intent-filter>
        <action android:name="com.google.codelabs.appauth.HANDLE_AUTHORIZATION_RESPONSE"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>

<activity android:name="net.openid.appauth.RedirectUriReceiverActivity" >
    <intent-filter>
        <action android:name="android.intent.action.VIEW"/>

        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>

        <data android:scheme="com.google.codelabs.appauth"/>

    </intent-filter>
</activity>

【问题讨论】:

    标签: android android-pendingintent appauth


    【解决方案1】:

    好的,所以在花了几天时间之后,我意识到我搞砸了重定向 URI 和 RedirectUriReceiverActivity 的数据元素。不知何故,this resource 帮助我了解了我所缺少的东西。

    在 AndroidManifest.xml 中,RedirectUriReceiverActivity 需要知道将完成发送回的位置。此外,我的重定向 uri(在我的 authReq 中)设置为外部地址,我将其更改为使用 Android 深层链接。

    【讨论】:

      猜你喜欢
      • 2013-01-17
      • 1970-01-01
      • 2014-08-02
      • 2012-02-28
      • 1970-01-01
      • 1970-01-01
      • 2013-08-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多