Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 39 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-security</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down Expand Up @@ -78,11 +78,11 @@
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.security</groupId>-->
<!-- <artifactId>spring-security-test</artifactId>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>com.discord4j</groupId>
<artifactId>discord4j-core</artifactId>
Expand All @@ -101,6 +101,36 @@
<artifactId>reactor-core</artifactId>
<version>3.4.10</version>
</dependency>

<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.32.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.oauth-client/google-oauth-client -->
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client</artifactId>
<version>1.32.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.apis/google-api-services-calendar -->
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-calendar</artifactId>
<version>v3-rev411-1.25.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.oauth-client/google-oauth-client-jetty -->
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-jetty</artifactId>
<version>1.32.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.api-client/google-api-client-jackson2 -->
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-jackson2</artifactId>
<version>1.20.0</version>
</dependency>
</dependencies>

<build>
Expand Down
46 changes: 0 additions & 46 deletions src/main/java/com/se21/Calendar/GoogleCalendar.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import org.json.simple.JSONObject;

public interface Calendar {
import java.security.GeneralSecurityException;

JSONObject authenticate(JSONObject auth);
public interface mainCalendar {

void authenticate() throws Exception;
JSONObject retrieveEvents(JSONObject req);
Enums.calApiResponse updateEvents(JSONObject req);
Enums.calApiResponse addEvents();
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/com/se21/calbot/CalBotApplication.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
package com.se21.calbot;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
public class CalBotApplication {
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
@EntityScan
@EnableAutoConfiguration
public class CalBotApplication implements ApplicationRunner {

@Autowired
GoogleCalendar calendar;

public static void main(String[] args) { SpringApplication.run(CalBotApplication.class, args);
}

@Override
public void run(ApplicationArguments args) throws Exception {
calendar.authenticate();
}
}
62 changes: 62 additions & 0 deletions src/main/java/com/se21/calbot/GoogleCalendar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.se21.calbot;

import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeRequestUrl;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.util.store.FileDataStoreFactory;
import com.google.api.services.calendar.CalendarScopes;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.List;


import org.springframework.stereotype.Component;

@Component
public class GoogleCalendar {

String accessToken;
String refreshToken;
String authToken;
private static final String CREDENTIALS_FILE_PATH = "/credentials.json";
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
private static final String TOKENS_DIRECTORY_PATH = "tokens";
private static final List<String> SCOPES = Collections.singletonList(CalendarScopes.CALENDAR);

public void authenticate() throws Exception {
// Load client secrets.

InputStream in = GoogleCalendar.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
if (in == null) {
throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
}
final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
// Build flow and trigger user authorization request.
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
.setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
.setAccessType("offline")
.build();
String url = flow.newAuthorizationUrl().setRedirectUri("http://localhost:8080/test").build();
LocalServerReceiver receiver = new LocalServerReceiver();
// Credential auth = new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
// System.out.println(auth.getAccessToken());
// auth.`

// GoogleAuthorizationCodeRequestUrl url = flow.newAuthorizationUrl();
System.out.println(url);
// return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
// return null;
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/se21/calbot/controllers/TestController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.se21.calbot.controllers;

import com.se21.calbot.GoogleCalendar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin(origins = "*")
public class TestController {

@RequestMapping(value = "/ping", method = RequestMethod.GET)
public String AuthenticateTest() throws Exception {
return "ping pong";
}
}