
org.riversun.oauth2.google.OAuthCommon Maven / Gradle / Ivy
/*
*
* Copyright 2016-2017 Tom Misawa, [email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in the
* Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
package org.riversun.oauth2.google;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Logger;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
/**
*
* @author Tom Misawa ([email protected])
*
*/
final class OAuthCommon {
private static final Logger LOGGER = Logger.getLogger(OAuthCommon.class.getName());
// SCOPE
public static final List SCOPES = new CopyOnWriteArrayList();
// Thread-safed
public static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
// Thread-safed
public static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
public static final GoogleClientSecrets getClientSecrets() throws IOException {
final InputStream is = OAuthCommon.class.getResourceAsStream("/client_secret.json");
final GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(is));
return clientSecrets;
}
public static final GoogleAuthorizationCodeFlow createFlow() throws IOException {
return new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT,
JSON_FACTORY,
getClientSecrets(),
SCOPES)
.build();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy