首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android AppAuth -跟随PendingIntent对象

Android AppAuth -跟随PendingIntent对象
EN

Stack Overflow用户
提问于 2019-08-28 13:34:20
回答 1查看 588关注 0票数 2

我一直试图在安卓系统中实现谷歌的AppAuth库,但我很难做到这一点。我一直试图跟踪谷歌指南,并将其应用到我自己的代码库中,但我仍然停留在待定的意图上。

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

performAuthorizationRequest()的Javadocs中,我看到了

“将调用所提供的{@链接PendingIntent完成PendingIntent}”。

那是什么意思?如何与已完成的pendingIntent对象进行交互?在创建挂起的意图时,我可以使用请求代码发送来检索上下文吗?

下面是我的代码:

代码语言:javascript
复制
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)

在我的舱单里,我增加了一些活动:

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-30 19:50:27

好的,在再花几天时间讨论这个问题之后,我意识到我搞砸了RedirectUriReceiverActivity的重定向URI和数据元素。不知怎么的,这一资源帮助我理解了我错过了什么。

在AndroidManifest.xml内部,RedirectUriReceiverActivity需要知道将补全发送回哪里。另外,我的重定向uri (在我的authReq中)被设置为外部地址,我将它更改为使用Android。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57693730

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档