简体   繁体   English

将对Google云端点的访问权限限制为Android应用

[英]Restrict access to google cloud endpoints to Android app

I'm using Android Studio to generate Google Cloud Endpoints for an Android app. 我正在使用Android Studio为Android应用生成Google Cloud Endpoints。 I've deployed the endpoints and they work ok. 我已经部署了端点,它们工作正常。

What I want to achieve is to enable access to the endpoints only to my app. 我想要实现的是只允许访问我的应用程序的端点。 All the documentation talks about how to enable authentication for users but I only need to restrict the access to the endpoints only from my app. 所有文档都讨论了如何为用户启用身份验证,但我只需要限制从我的应用程序访问端点。 I don't want to use user credentials because the api does not use that. 我不想使用用户凭据,因为api不使用它。

What I tried is creating a client ID for my app in the Google Console and adding to the APi annotation 我尝试的是在Google控制台中为我的应用创建客户端ID并添加到APi注释

@Api(name = "messageEndpoint", clientIds = {Ids.WEB_CLIENT_ID, Ids.ANDROID_CLIENT_ID, Ids.API_EXPLORER}, audiences = {Ids.ANDROID_AUDIENCE}}

And for each API method, I've added a User parameter and check if the user is null or not. 对于每个API方法,我添加了一个User参数并检查用户是否为null。 My understanding is that the user should be not null if the API is called from one of the client IDS. 我的理解是,如果从其中一个客户端IDS调用API,则用户不应为null。 But user is always null. 但是用户总是为空。

Am I missing something? 我错过了什么吗?

In my Android app I have 在我的Android应用程序中,我有

GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(DelegateActivity.this, "server:client_id:" + Ids.ANDROID_AUDIENCE);
MessageEndpoint.Builder endpointBuilder = new MessageEndpoint.Builder(
                        AndroidHttp.newCompatibleTransport(), new JacksonFactory(),
                        credential);

And the exception I am getting is: 我得到的例外是:

java.lang.NullPointerException: [qi] accountName cannot be null.
                        E   at android.os.Parcel.readException(Parcel.java:1431)
                        E   at android.os.Parcel.readException(Parcel.java:1379)
                        E   at com.google.android.gms.internal.a$a$a.a(Unknown Source)
                        E   at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
                        E   at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
                        E   at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:277)
                        E   at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:301)
                        E   at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:854)
                        E   at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
                        E   at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
                        E   at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)

My understanding is that user will be null in the situation you described: authenticating the app and not the user. 我的理解是,在您描述的情况下,用户将为null:验证应用程序而不是用户。

If the app authentication fails then your endpoint won't even be called. 如果应用程序身份验证失败,则甚至不会调用您的端点。

I assume that the string "[qi] accountName cannot be null." 我假设字符串“[qi] accountName不能为空”。 is from your app? 来自你的应用程序?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何限制Google App Engine端点API只能访问我的Android应用程序? - How do I restrict Google App Engine Endpoints API access to only my Android applications? Android客户端-使用Google Cloud Endpoints的Google App引擎身份验证 - Android Client - Google App engine authentication using Google Cloud Endpoints 使用适用于Google App Engine的Cloud Endpoints对Android App进行本地测试 - Local testing for Android App using Cloud Endpoints for Google App Engine 如何在Android客户端上访问特定的Google Cloud Endpoints API版本 - How to access specific Google Cloud Endpoints API versions on android clients Google在Android应用中登录以使用Cloud Endpoints后端 - Google signin in Android app to consume Cloud Endpoints backend 将android应用连接到Google Cloud Endpoints时出错:找不到课程 - Error connecting android app to Google Cloud Endpoints: could not find class 使用Google Cloud Endpoints的Android应用:数据存储区与SQL - Android app using Google cloud Endpoints: Datastore vs SQL 如何将敏感数据从Android应用传递到Google Cloud Endpoints? - How to pass sensitive data to Google Cloud Endpoints from Android app? Google Cloud端点(应用程式引擎)+与Android的oauth2整合 - Google cloud endpoints (app engine) + oauth2 integration with android 将GAE API(端点)限制为Android应用 - Restrict GAE API (Endpoints) to Android app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM