I'm developing an android app and I want to restrict access to my API to my website and mobile application. I'm not interested in having the user login into my app, rather, registering the client.
I've refrenced these resources for this task:
- how to make google endpoints inaccessible from the web?
- How do I protect my API that was built using Google Cloud Endpoints?
- https://cloud.google.com/appengine/docs/java/endpoints/add-authorization-backend
- How do I restrict Google App Engine Endpoints API access to only my Android applications?
Here is what I did thus far:
- Generated an android and web client api key from the google cloud console. It looks something like this: ALzfShCF_mD_IVlVVVf2783TG9FG8x7u0s-ZFQE (not real key)
Made a constants class, added these to my API declaration for clientIds
clientId{android_key,web_key} && audience{web_key,android_audiance}
Added a User user param to each method
Rebuilt project, deployed.
All of these resources seemed helpful, especially the documentation. However, I didn't notice any difference. I expected to see, after I followed the documentation and redeploy my backend, both my website and app fail to call my endpoint functions. However, they both worked flawlessly.
Would following these posts or documentation prove my case, or is there something else I must do? I also dont want unauthorized access to my API explorer as well!
Any help would be greatly appreciated!
Edit:
I'm using the wrong keys, I was using the API key instead of the CLIENT Id. Once I updated that I saw that my API requests are failing because the user param is null. Now my question is, how can I not pass a non-null user object without getting the user to login?
I tried making a GoogleAccountCredintal and passing it to my ApiBuilder in my Async task, but its always null.
GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(context,APIClientKeys.ANDROID_CLIENT_ID);
MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(),
new AndroidJsonFactory(), credential) ...