Does anyone know the correct setup for the cloud project and redirect URL within the application for the following case?
Setup:
- Spring + Apache Wicket
- The application is installed on a server (Windows, Linux*) and accessed on the intranet via browser.
*) with or without desktop
Requirements:
- Access to one or more Gmail-Accounts to retrieve emails, mark emails as read and move emails to trash
- Credentials are stored for each account separately on the server
- Creation of the access is done on a client by an admin user in the browser
- Consent for an account is done only once on creation, emails are retrieved in a background thread (no user interaction, token is refreshed automatically)
- No additional setups on the clients (e.g. changing the host-file, running a background-process/listener); Client could also be a mobile device accessing the intranet
Scopes:
- Non-Restricted: userinfo.email
- Restricted: gmail.modify
Cloud projects setups/attempts:
Cloud project: Desktop-App; Application:- Does not work - the consent screen is opened on the server if this is usedAuthorizationCodeInstalledApp.authorize
Cloud project: Desktop-App; Application:- Worked but Google is discontinuing ooburn:ietf:wg:oauth:2.0:oob
as redirect url and popup on the clientCurrent: Cloud project: Web-App with a public redirect url; Application: redirected to our website - only to show the auth code, which can be pasted in the application open in the browser
public String getAuthorizationUrl(String clientId, String clientSecret, String credentialPath) { final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance(); final List<String> SCOPES = Arrays.asList(new String[] {GmailScopes.GMAIL_MODIFY, Oauth2Scopes.USERINFO_EMAIL}); Details details = new Details(); details.setClientId(clientId); details.setClientSecret(clientSecret); GoogleClientSecrets clientSecrets = new GoogleClientSecrets(); clientSecrets.setInstalled(details); // Build flow and trigger user authorization request. GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder( HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES) .setDataStoreFactory(new FileDataStoreFactory(new File(credentialPath))) .setApprovalPrompt("force") .setAccessType("offline") .build(); /* approval prompt and access type were not needed for desktop-app; * refresh token was generated anyway, they had to be added for web-app * to get a refresh token */ String redirUri = "https://example.com/redirect"; AuthorizationCodeRequestUrl authorizationUrl = flow.newAuthorizationUrl().setRedirectUri(redirUri); return authorizationUrl.build(); }
Google Oauth verification: Google says that according to the generated traffic, the app is running on a web server and we need to change it to a local URL, otherwise we need a security assessment because the data is stored on a web server. While it's technically true that it's running on a web server, it's an intranet server. It's not possible to define a fixed local URL since the servers IP could be different for each user that is installing the app on his server.