我一直试图在安卓系统中实现谷歌的AppAuth库,但我很难做到这一点。我一直试图跟踪谷歌指南,并将其应用到我自己的代码库中,但我仍然停留在待定的意图上。
更具体地说,当我调用performAuthorizationRequest()方法时,模拟器可以按照重定向获得它的自定义选项卡中的auth代码(我可以看到它)。但是,没有调用任何处理程序。我尝试过添加onNewIntent()、onActivityResult()和onResume(),但它们都没有被调用。
从performAuthorizationRequest()的Javadocs中,我看到了
“将调用所提供的{@链接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>发布于 2019-08-30 19:50:27
好的,在再花几天时间讨论这个问题之后,我意识到我搞砸了RedirectUriReceiverActivity的重定向URI和数据元素。不知怎么的,这一资源帮助我理解了我错过了什么。
在AndroidManifest.xml内部,RedirectUriReceiverActivity需要知道将补全发送回哪里。另外,我的重定向uri (在我的authReq中)被设置为外部地址,我将它更改为使用Android。
https://stackoverflow.com/questions/57693730
复制相似问题