Google 캘린더를 인증하는 방법을 찾고 있습니다. 지금 우리가 앱을 코딩 한 방법은 인증 URL을 생성하고 사용자가 해당 URL을 탐색하고 '성공 코드'를 복사하여 프로그램에 붙여 넣은 다음 인증 토큰을 처리하도록 입력하는 것입니다.Java : Google 캘린더 인증
나는 그 과정을 자동화하는 방법을 찾고있다. 우리의 앱이 사용자의 브라우저 창에서 생성 된 성공 코드를 직접 읽게하기 위해서. 이렇게하면 사용자가 직접 코드를 복사하여 붙여 넣을 필요가 없습니다.
이러한 기능을 구현하는 방법과이를 위해 사용해야하는 라이브러리 또는 특정 방법을 알려 주시면 감사하겠습니다.
이
는 사용자가 탐색 할 수있는 URL을 생성하는 방법이며,이 URL 반환public static String generateNewTokenStep1() {
HttpTransport httpTransport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
// Create the authorization code flow manager
Set<String> scope = Collections.singleton(CalendarScopes.CALENDAR);
String clientId = "_______";
String clientSecret = "__________";
AuthorizationCodeFlow.Builder codeFlowBuilder = new GoogleAuthorizationCodeFlow.Builder(
httpTransport, jsonFactory, clientId, clientSecret, scope);
codeFlow = codeFlowBuilder.build();
String userId = USER_ID;
// "redirect" to the authentication url
redirectUri = "urn:ietf:wg:oauth:2.0:oob";
AuthorizationCodeRequestUrl authorizationUrl = codeFlow
.newAuthorizationUrl();
authorizationUrl.setRedirectUri(redirectUri);
return authorizationUrl.toString();
}
이 구글에 의해 생성 된 성공 코드에 걸리는 방법입니다.
public static String generateNewTokenStep2(String userInput) {
String code = userInput;
AuthorizationCodeTokenRequest tokenRequest = codeFlow
.newTokenRequest(code);
tokenRequest.setRedirectUri(redirectUri);
TokenResponse tokenResponse = null;
try {
tokenResponse = tokenRequest.execute();
} catch (IOException tokenRequestFailed) {
System.err.println("Token request failed");
}
System.out.println(tokenResponse.getAccessToken());
addToDb(tokenResponse.getAccessToken());
return tokenResponse.getAccessToken();
}
redirect_uri를 사용하여 원하는 포트 또는 웹 서버에 대한 응답을받을 수 있습니까? https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi – luc