Android emulator does not gain access to authorized api - google-app-engine

The Android Emulator (Nexus) in Android Studio does not gain access to authorized api (Endpoints from Google cloud App Engine).
The following code works fine with a physical device but not with the emulator:
credential = GoogleAccountCredential.usingAudience(context,
"server:client_id:" + "xyz-xyz.apps.googleusercontent.com");
credential.setSelectedAccountName("xyz#gmail.com");
builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(), new
AndroidJsonFactory(), credential).setRootUrl("https://babydo-xyz.appspot" +
".com/_ah/api/").setApplicationName("BackendTest");
The following error shows the Android Monitor:
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: ch.appfactory.kusi.backendtest, PID: 8074
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
Caused by: java.lang.IllegalArgumentException: the name must not be empty: null
at android.accounts.Account.<init>(Account.java:48)
at com.google.android.gms.auth.zzd.getToken(Unknown Source)
at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
The App Engine console shows no server error.
Interestingly, the emulator has access to the api and work fine, when no authentication is implemented, according to the following Code:
builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(), new
AndroidJsonFactory(), null).setRootUrl("https://babydo-xyz.appspot" +
".com/_ah/api/");
Does anyone know what to consider, when the emulator make authenticated calls?
Thanks for answering

Related

App engine local host not working on Eclipse after Java updates on 20/01/2021

After a popup window has shown asks to confirm Java updates, the App engine could not be started again and Eclipse showing the following error:
INFO: Overwriting system property key 'file.encoding', value 'Cp1252' with value 'UTF-8' from 'C:\Users\XXXX\eclipse-workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\XXXX\WEB-INF\appengine-web.xml'
java.lang.NullPointerException
at java.base/java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1011)
at java.base/java.util.concurrent.ConcurrentHashMap.put(ConcurrentHashMap.java:1006)
at java.base/java.util.Properties.put(Properties.java:1334)
at java.base/java.util.Collections$CheckedMap.put(Collections.java:3701)
at com.google.appengine.tools.development.SharedMain.setTimeZone(SharedMain.java:183)
at com.google.appengine.tools.development.SharedMain.postServerActions(SharedMain.java:152)
at com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:398)
at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:45)
at com.google.appengine.tools.development.DevAppServerMain.run(DevAppServerMain.java:257)
at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:248)

Using MSAL in CloudShell

I've validated the MSAL auth path using the desktop PowerShell 5.1 and 7.0 applications. However, all of the authentication paths which worked on the desktop are not working in CloudShell -
PS /home/michael/CSTest/0.0.2/MicrosoftTeams> connect-microsoftteams
Connect-MicrosoftTeams: One or more errors occurred. (Unable to open a web page using xdg-open. See inner exception for details. Possible causes for this error are: xdg-open is not installed or it cannot find a way to open an url - make sure you can open a web page by invoking from a terminal: xdg-open https://www.bing.com )
Connect-MicrosoftTeams: Unable to open a web page using xdg-open. See inner exception for details. Possible causes for this error are: xdg-open is not installed or it cannot find a way to open an url - make sure you can open a web page by invoking from a terminal: xdg-open https://www.bing.com
Connect-MicrosoftTeams: No such file or directory
Connect-MicrosoftTeams: One or more errors occurred. (Unable to open a web page using xdg-open. See inner exception for details. Possible causes for this error are: xdg-open is not installed or it cannot find a way to open an url - make sure you can open a web page by invoking from a terminal: xdg-open https://www.bing.com )
PS /home/michael/CSTest/0.0.2/MicrosoftTeams> connect-microsoftteams -UseDeviceAuthentication
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code BRZPG2UNE to authenticate.
Connect-MicrosoftTeams: One or more errors occurred. (Windows Data Protection API (DPAPI) is not supported on this platform.)
Connect-MicrosoftTeams: Windows Data Protection API (DPAPI) is not supported on this platform.
Connect-MicrosoftTeams: One or more errors occurred. (Windows Data Protection API (DPAPI) is not supported on this platform.)
PS /home/michael/CSTest/0.0.2/MicrosoftTeams> connect-microsoftteams -AccountId miluong#microsoft.com
Connect-MicrosoftTeams: One or more errors occurred. (Federated service at https://msft.sts.microsoft.com/adfs/services/trust/13/windowstransport returned error: )
Connect-MicrosoftTeams: Federated service at https://msft.sts.microsoft.com/adfs/services/trust/13/windowstransport returned error:
Connect-MicrosoftTeams: Federated service at https://msft.sts.microsoft.com/adfs/services/trust/13/windowstransport returned error:
Connect-MicrosoftTeams: One or more errors occurred. (Federated service at https://msft.sts.microsoft.com/adfs/services/trust/13/windowstransport returned error: )
How do I enable support for managed identity?
How do I get interactive auth flow to work without xdg-open? Currently CloudShell does not install xdg-open
Is there a recommended path to try to acquire a token without DPAPI? CloudShell works in a Linux environment and DPAPI only supports Windows.
Do you know of any PS modules which use MSAL that are working in CloudShell?
xdg-open does not work and is not planned to be supported in CloudShell
The DPAPI error was because I was trying to protect the token by encrypting it at rest
Integrated Windows Authentication is not a supported workflow in CloudShell because it's a Linux based environment.

Google App Engine Remote API Service Account Credential error

I am currently using remote api for google app engine to connect to a datastore from another GAE project.
Below is my code:
RemoteApiOptions options;
options = new RemoteApiOptions().server("project_id.appspot.com",443).useServiceAccountCredential("project#project-168016.iam.gserviceaccount.com","EPHIMS-cbe10d4a5105.json");
RemoteApiInstaller installer = new RemoteApiInstaller();
installer.install(options);
When I run my application, I get the error below:
java.lang.RuntimeException: Failed to build service account credential.
Caused by: java.io.FileNotFoundException: EPHIMS-cbe10d4a5105.json (The system cannot find the file specified)
at java.io.FileInputStream.open0(Native Method)
Does anyone know how to fix this? - I have created an environment variable and set it to the path where the .json file is, this still does not work.

Remote implementation for app_identity_service.GetAccessToken failed at GAE PHP dev

Google App Engine SDK for PHP (at local environment) returns error on any try to use Google Cloud Storage. Error message is:
Fatal error: Uncaught exception 'google\appengine\runtime\RPCFailedError' with message 'Remote implementation for app_identity_service.GetAccessToken failed' in /media/data/home/vladimir/setup/gae/google_appengine/php/sdk/google/appengine/runtime/RemoteApiProxy.php on line 92
It exactly repeats the problem described here:
App engine update breaks CloudStorage in dev php env
Test code from the question above shows the same result.
I tried App Engine SDK for PHP versions 1.9.19, 1.9.20, 1.9.21 without success.
On Win10 this issue can be solved by generating an application-default credentials file:
D:\Workspace\Sourcecode>gcloud auth application-default login
Credentials saved to file: [C:\Users\Otje\AppData\Roaming\gcloud\application_default_credentials.json]
And then setting the environment in commandline:
D:\Workspace\Sourcecode>SET GOOGLE_APPLICATION_DEFAULT=C:\Users\Otje\AppData\Roaming\gcloud\application_default_credentials.json
Seems to me GAE on local just outputs limited error information when it can't find the right credentials to succesfully connect to remote endpoint.
It seems that it was GAE's server side issue. They fixed it. I discovered that it started to work as expected today without any changes applied by me.

Google app Engine Application error

I am trying to run the guestbook application https://developers.google.com/appengine/docs/java/gettingstarted/creating but getting error:
Error screenshot at the url http://goo.gl/rw0dnR
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
ERROR: transport error 202: connect failed: Connection timed out
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [../../../src/share/back/debugInit.c:741]
I tried it on Eclipse. In Eclipse I click Run menu and then "Debug As"->"Web application". The error popup says:
Problem Occurred: 'Launching Guestbook' has encountered a
problem.Cannot connect to VM. (Cannot connect to VM
com.sun.jdi.connect.TransportTimeoutException)
Could anyone help me troubleshhot.
The code is:
package guestbook;
import java.io.IOException;
import javax.servlet.http.*;
public class GuestbookServlet extends HttpServlet {
#Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, world");
}
}
The code looks fine and it evidently compiles without error. The problem appears to be rather low down in the run time environment of Eclipse, the AppEngine development environment or the Jetty web application server.
I suggest uninstalling and re-installing Eclipse and the AppEngine SDK, or better still try with another computer.
Is another process listening on port 8888? On Windows use netstat -an at a command prompt to check.
You could try another port number. In Eclipse select Run, Debug Configurations..., your project name, Server. Change from 8888 and try again.
To prove that Eclipse is not the problem, temporarily use a fresh copy in a spare directory. Get it from from Eclipse Downloads, selecting "Eclipse IDE for Java EE Developers" and the appropriate 32 bit or 64 bit version. Add both the Google Plugin for Eclipse and App Engine Java SDK using the Eclipse Help -> Install new software... options, working with https://dl.google.com/eclipse/plugin/4.3 as the available software site.

Resources