i have created a REST Api with Spring boot and to send emails, Ive implemented the Gmail API. When im starting the api on my server for the first time, this comes of course:
Please open the following address in your browser: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=XXX.apps.googleusercontent.com&redirect_uri=http://localhost:8888/Callback&response_type=code&scope=https://www.googleapis.com/auth/gmail.send
But here comes the problem. When im clicking on the link, Im gettin redirected to localhost:8888/… but as this does not runs on my computer but on the server the verification cant be executed. So my question is: Are there any other ways to verificate? Or is there a solution for the problem?
Ive tried to change the gmai.json (where the token is saved) and changed redirect_uris to the servers adress. Didnt helped.
{ "web": { "client_id":"nope", "auth_uri":"https://accounts.google.com/o/oauth2/auth", "token_uri": "https://accounts.google.com/o/oauth2/token", "client_secret":"nope", "redirect_uris": "http://sva-doppelturnier.de:8888" } }
and that is the credential funktion, whos been called to verificate the token
` private static Credential getCredentials(final NetHttpTransport httpTransport, GsonFactory jsonFactory)
throws IOException {
InputStream inputStream = MailService.class.getResourceAsStream("/gmail.json");
if (inputStream == null) {
logger.error("Unable to load Gmail credentials file.");
return null;
}
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(jsonFactory, new InputStreamReader(inputStream));
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
httpTransport, jsonFactory, clientSecrets, Set.of(GMAIL_SEND))
.setDataStoreFactory(new FileDataStoreFactory(Paths.get("tokens").toFile()))
.setAccessType("offline")
.build();
LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}`
Thanks a lot!
im searching since 4 hours…
LaLeX1491 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.