Java Action to generate a Google Credentials Token for a Google Service Account

0
Hi I try to setup a Java Action to get a Google Credentials Token, which i can use to authenticate with oAuth to Google API with a Google Service Account. I have creates a Google Service Account with a Key. This key i transfered as InputJSON, but i get no token back and no error message. I am not sure if this is an issue on mendix side or on google side. Has anyone experiance with this? Thanks Stephan        GoogleCredential credential = GoogleCredential.fromStream(new ByteArrayInputStream(InputJSON.getBytes()))         .createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform"));   // This file was generated by Mendix Studio Pro. // // WARNING: Only the following code will be retained when actions are regenerated: // - the import list // - the code between BEGIN USER CODE and END USER CODE // - the code between BEGIN EXTRA CODE and END EXTRA CODE // Other code you write will be lost the next time you deploy the project. // Special characters, e.g., é, ö, à, etc. are supported in comments. package workflowengine.actions; import com.mendix.systemwideinterfaces.core.IContext; import com.mendix.webui.CustomJavaAction; import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; import com.google.common.collect.Lists; import java.io.ByteArrayInputStream; import java.util.*; import com.mendix.systemwideinterfaces.core.IMendixObject; import com.google.api.client.json.GenericJson; import com.google.api.client.json.JsonFactory; import com.google.api.client.json.JsonObjectParser; import com.google.api.client.util.Preconditions; import java.io.IOException; import java.io.InputStream; public class GoogleCredentials extends CustomJavaAction<java.lang.String> {     private java.lang.String InputJSON;     public GoogleCredentials(IContext context, java.lang.String InputJSON)     {         super(context);         this.InputJSON = InputJSON;     }     @java.lang.Override     public java.lang.String executeAction() throws Exception     {         // BEGIN USER CODE                  ByteArrayInputStream str = new ByteArrayInputStream(InputJSON.getBytes());                  GoogleCredential credential = GoogleCredential.fromStream(new ByteArrayInputStream(InputJSON.getBytes()))         .createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform"));              return credential.getAccessToken();         // END USER CODE     }     /**      * Returns a string representation of this action      */     @java.lang.Override     public java.lang.String toString()     {         return "GoogleCredentials";     }     // BEGIN EXTRA CODE     // END EXTRA CODE
asked
1 answers
0

Hi Stephan, 

The functionality you are building is already available in the JWT module in the App Store. You could just use this module, or check out the Java functions in that module to see how this action is performed there!

answered